在CSProj中使用通配符时如何在xaml文件下嵌套xaml.cs

kla*_*sel 4 c# msbuild csproj

我对csproj文件有疑问。

由于我拥有大量的源库,因此我正在尝试最大程度地减少项目文件上的冲突(与团队一起开发时)。

我设法通过使用如下标记消除了大多数碰撞:

<Compile Include="Services\**\*.cs" /> 
Run Code Online (Sandbox Code Playgroud)

对于普通的cs文件和

<Page Include="Entities\**\*.xaml">
  <SubType>Designer</SubType>
  <Generator>MSBuild:Compile</Generator>
</Page>
Run Code Online (Sandbox Code Playgroud)

用于xaml和代码隐藏。

不幸的是,我松开了.xaml和.xaml.cs对的分组,这是可以忍受的,但是笨拙。

有什么办法为这些创建通用模式吗?

<Compile Include="MainWindow.xaml.cs">
  <DependentUpon>MainWindow.xaml</DependentUpon>
  <SubType>Code</SubType>
</Compile>
Run Code Online (Sandbox Code Playgroud)

我知道分裂csproj本身的可能性,但这将禁止解决方案范围内的搜索,因此这是不可行的

Mar*_*ich 6

使用MSBuild 15的静态更新语法,您可以执行

 <Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />
Run Code Online (Sandbox Code Playgroud)

这里的技巧是MSbuild将路径分为Filenamefoo.xaml.cs=> foo.xaml)和Extensionfoo.xaml.cs=> .cs),因此%(Filename)可以用来引用xaml文件。