I realize that XAML files are not supported (#1467); still, they seem to work mostly fine when using the following project file (WPF):
<!-- https://stackoverflow.com/q/43693591/2978652 -->
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
<TargetFramework>net47</TargetFramework>
<OutputType>WinExe</OutputType>
<StartupObject />
<NeutralLanguage>en</NeutralLanguage>
</PropertyGroup>
<ItemGroup>
<!-- App.xaml -->
<ApplicationDefinition Include="App.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</ApplicationDefinition>
<!-- XAML elements -->
<Page Include="**\*.xaml" Exclude="App.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</Page>
<Compile Update="**\*.xaml.cs" SubType="Code" DependentUpon="%(Filename)" />
<!-- Resources -->
<EmbeddedResource Update="Properties\Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
<Compile Update="Properties\Resources.Designer.cs" AutoGen="True" DependentUpon="Resources.resx" DesignTime="True" />
<!-- Settings -->
<None Update="Properties\Settings.settings" Generator="SettingsSingleFileGenerator" LastGenOutput="Settings.Designer.cs" />
<Compile Update="Properties\Settings.Designer.cs" AutoGen="True" DependentUpon="Settings.settings" />
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<!-- https://github.com/dotnet/project-system/issues/2488 -->
<Target Name="WorkaroundForXAMLIntellisenseBuildIssue" AfterTargets="_CheckCompileDesignTimePrerequisite">
<PropertyGroup>
<BuildingProject>false</BuildingProject>
</PropertyGroup>
</Target>
</Project>
The only thing I've come across that doesn't work is that changes to XAML files, while immediately visible in the designer, won't make the project recompile automatically when run. Which is a bit annoying, since I have to force rebuild the WPF project before I run it, which rebuilds all its dependencies too.
Is there a simple workaround to make changed XAML files cause automatic recompilation when using the new project system?
Have you tried switching the generator to <Generator>MSBuild:Compile</Generator>? I have seen that in many examples of WPF projects running in the new project system. After making that change everything seems to be working for me except for go to definition from xaml to code behind. The go to definition can be worked around by using Resharper's go to definition but I still haven't found a means in stock Visual Studio to get it to work.
Changed it both places, but unfortunately it had no effect.
I believe there should be a workaround of adding the xaml files to the update to date input item group.
@Pilchie can you post the actual XML to make this work?
I think adding:
<ItemGroup>
<UpToDateCheckInput Include="**\*.xaml" />
</ItemGroup>
Should work. @panopticoncentral does that seem right?
Also tagging @onovotny on this issue.
That seems correct. I'll take a look soon to see what's going on. Probably because the source file type is missing from our "known" list.
@Pilchie works admirably, thanks!
@cmeeren Could you go to Tools > Options > Projects and Solutions > .NET Core and change the Logging Level drop down to "Verbose"? Then remove the workaround, reproduce the problem, go to the build output window, copy everything there and attach it to the bug? Thanks!
@panopticoncentral Sorry I haven't been able to look at it yet; it's been a very busy week. It's on my todo list, though.
Finally got around to it. Here's a repro solution and the log you requested.
@cmeeren What version are you running? On the build I'm running the up to date check correctly took the xaml files into account, so trying to figure out what could be the difference.
VS 15.6.4.
I believe this was fixed by https://github.com/dotnet/project-system/pull/3290 in 15.7.
This is still reproducible in 15.7.5 using the repro solution above.
Most helpful comment
I think adding:
Should work. @panopticoncentral does that seem right?