我有一些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
。 - Mr Qian