【发布时间】:2020-07-22 17:05:57
【问题描述】:
我正在生成许多 C# 文件。我希望它们自动嵌套在 Visual Studio 解决方案资源管理器中匹配的 C# 文件下。例如,Foo.Generated.cs 和 Bar.Generated.cs 将分别嵌套在 Foo.cs 和 Bar.cs 下。
如果可能的话,我希望能够在我的 Directory.Build.props 文件中管理它,这样我的解决方案中的所有类库都将具有相同的行为。
版本
- .NET Core 3.1
- Visual Studio 2019 (16.5.3)
尝试 A 失败:
<Compile Update="**\*Generated.cs">
<DependentUpon>$([System.String]::Copy(%(Filename)).Replace('.Generated', '.cs'))</DependentUpon>
</Compile>
尝试 B 失败:
<Compile Update="**\*Generated.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
尝试 C 失败:
<Compile Update="**\*Generated.cs">
<DependentUpon>%(Filename).cs</DependentUpon>
</Compile>
上面的方法也试过了:
<ItemGroup>
<ProjectCapability Include="DynamicDependentFile" />
<ProjectCapability Include="DynamicFileNesting" />
</ItemGroup>
【问题讨论】:
-
请使用
Directory.Build.targets而不是Directory.Build.props
标签: c# visual-studio .net-core msbuild csproj