我正在尝试编写代码生成工具.对于此工具,重要的是生成的代码在构建之前可用(即,对于IntelliSense).我知道Visual Studio将至少部分地自动评估项目构建计划以生成IntelliSense,但我找不到有关细节的更多信息.
作为一个更简单的例子,假设我想要使用构建操作获取所有项目None并进行编译.我有一个这样的项目:
<Project [...]>
[...]
<Compile Include="Foo.cs" />
<None Include="Bar.cs" />
</Project>
Run Code Online (Sandbox Code Playgroud)
Bar.cs编译的一种方法是将以下内容添加到项目中:
<PropertyGroup>
<CoreCompileDependsOn>
$(CoreCompileDependsOn);IndirectCompile
</CoreCompileDependsOn>
</PropertyGroup>
<Target Name="IndirectCompile">
<CreateItem Include="@(None)">
<Output ItemName="Compile" TaskParameter="Include" />
</CreateItem>
</Target>
Run Code Online (Sandbox Code Playgroud)
如果我这样做,这样一来,就好像Visual Studio中的作用基本相同Bar.cs有Compile开始与行动.IntelliSense完全可用; 如果我进行了更改,Bar.cs我在编辑时会在IntelliSense中立即反映(好吧,就像后台操作一样直接)Foo.cs,依此类推.
但是,请说不是直接编译None条目,而是将其复制到obj目录中,然后从那里编译它.我可以通过将IndirectCompile目标更改为:
<Target Name="IndirectCompile"
Inputs="@(None)"
Outputs="@(None->'$(IntermediateOutputPath)%(FileName).g.cs')"
>
<Copy SourceFiles="@(None)"
DestinationFiles="@(None->'$(IntermediateOutputPath)%(FileName).g.cs')"
>
<Output TaskParameter="DestinationFiles" ItemName="Compile" />
</Copy>
</Target>
Run Code Online (Sandbox Code Playgroud)
这样做会导致IntelliSense停止更新.该任务适用于构建,依赖性分析和增量构建工作,Visual Studio在保存输入文件时会停止自动运行它.
因此,这导致标题问题:Visual Studio如何选择为IntelliSense运行目标?我发现的唯一官方文档就是这个,特别是"Design-Time IntelliSense"部分.我很确定我的代码符合所有这些标准.我错过了什么?