Visual Studio csproj通配符中的智能文件嵌套

ehxuflar  于 2022-12-30  发布在  其他
关注(0)|答案(1)|浏览(237)

我需要更好的文件嵌套。
我有索引.剃刀,索引.剃刀. cs,索引.模型. cs,索引.界面. cs在网页文件夹内。
在csproj中
我有

  1. <ItemGroup>
  2. <Compile Update="Pages\Index.razor.cs" DependentUpon="Pages\Index.razor" />
  3. <Compile Update="Pages\Index.Model.cs" DependentUpon="Pages\Index.razor" />
  4. <Compile Update="Pages\Index.Interface.cs" DependentUpon="Pages\Index.razor" />
  5. </ItemGroup>

我在通配符中创建了此功能

  1. <ItemGroup>
  2. <Compile Update="**\*.Interface.cs" DependentUpon="$([System.String]::Copy('%(FileName)').Replace('.Interface', '.razor'))" />
  3. <Compile Update="**\*.Model.cs" DependentUpon="$([System.String]::Copy('%(FileName)').Replace('.Model', '.razor'))" />
  4. </ItemGroup>

我想要更好的版本

  1. <ItemGroup>
  2. <Compile Update="**\*.Interface.cs" Condition="Exists('Check Razor')" >
  3. <DependentUpon>"$([System.String]::Copy('%(FileName)').Replace('.Interface', '.razor'))"</DependentUpon>
  4. </Compile>
  5. <Compile Update="**\*.Model.cs" Condition="Exists('Check Razor')" >
  6. <DependentUpon>"$([System.String]::Copy('%(FileName)').Replace('.Model', '.razor'))"</DependentUpon>
  7. </Compile>
  8. <Compile Update="**\*.Interface.cs" Condition="Exists('Check cshtml')" >
  9. <DependentUpon>"$([System.String]::Copy('%(FileName)').Replace('.Interface', '.cshtml'))"</DependentUpon>
  10. </Compile>
  11. <Compile Update="**\*.Model.cs" Condition="Exists('Check cshtml')" >
  12. <DependentUpon>"$([System.String]::Copy('%(FileName)').Replace('.Model', '.cshtml'))"</DependentUpon>
  13. </Compile>
  14. Need to check here also
  15. <Compile Update="**\*.Interface.cs" DependentUpon="$([System.String]::Copy('%(FileName)').Replace('.Interface', '.cs'))" />
  16. <Compile Update="**\*.Model.cs" DependentUpon="$([System.String]::Copy('%(FileName)').Replace('.Model', '.cs'))" />
  17. </ItemGroup>

这样我就可以在cshtml和razor项目中使用隔离,而不需要hasle。

acruukt9

acruukt91#

例如,要在xaml中工作,可以使用MSBuild15的静态更新语法。

  1. <Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />

MSbuild将路径拆分为(=〉)和(=〉),因此可以用它来引用xaml文件。
文件名foo.xaml.csfoo. xaml扩展名foo.xaml.cs.cs%(文件名)

相关问题