project-system: Project does not automatically recompile when XAML files change, using new csproj format

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?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 15 (7 by maintainers)

Most upvoted comments

I think adding:

<ItemGroup>
  <UpToDateCheckInput Include="**\*.xaml" />
</ItemGroup>

Should work. @panopticoncentral does that seem right?