【发布时间】:2015-06-15 21:11:47
【问题描述】:
如何在解决方案资源管理器的文件列表中包含文件而不将其作为编译依赖项包含在内?
我有一个生成 .cs 文件的 .targets 文件,类似于the examples in this answer。
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CoreCompileDependsOn>$(CoreCompileDependsOn);GenerateCode</CoreCompileDependsOn>
</PropertyGroup>
<ItemGroup>
<Sources Include="..\sources\*.txt" />
</ItemGroup>
<Target Name="GenerateCode" Inputs="@(Sources)" Outputs="@(Sources->'generated\%(Filename).cs')">
<!-- run executable that generates files -->
<ItemGroup>
<Compile Include="generated\*.cs" />
</ItemGroup>
</Target>
</Project>
这会正确构建,并且连续构建不会不必要地重新构建项目。生成的 .cs 文件在解决方案资源管理器中不可见。智能感知也找不到生成的代码。
如果我在 .csproj 中添加带有 ItemGroups 的文件,生成的文件在解决方案资源管理器中可见,但后续构建会导致不必要地重新构建项目。智能感知仍然找不到生成的代码。
<ItemGroup>
<Sources Include="..\sources\*.txt">
<Link>sources\%(Filename)%(Extension)</Link>
</Sources>
<!-- using None instead of Compile on the next line makes no difference -->
<Compile Include="@(Sources->'generated\%(Filename).cs')">
<Generator>MSBuild:Compile</Generator>
<Link></Link>
</Compile>
</ItemGroup>
我如何告诉 msbuild 项目中包含的 .cs 文件对构建无关紧要,因此不应触发重新构建整个项目?
【问题讨论】:
标签: c# visual-studio msbuild intellisense