How does Visual Studio decide when and how to rebuild IntelliSense?

I am trying to write a code generation tool. For this tool, it is important that the generated code is available before construction (i.e. For IntelliSense). I know that Visual Studio will at least partially evaluate the project plan automatically to create IntelliSense, but I can’t find much information about the details.

As a simpler example, let's say I want to take all the elements with an action None string and compile them. I have a project like this:

 <Project [...]> [...] <Compile Include="Foo.cs" /> <None Include="Bar.cs" /> </Project> 

One way to get Bar.cs to compile is to add the following to your project:

 <PropertyGroup> <CoreCompileDependsOn> $(CoreCompileDependsOn);IndirectCompile </CoreCompileDependsOn> </PropertyGroup> <Target Name="IndirectCompile"> <CreateItem Include="@(None)"> <Output ItemName="Compile" TaskParameter="Include" /> </CreateItem> </Target> 

If I do this, Visual Studio acts basically the same as if Bar.cs had a Compile action to start with. IntelliSense is fully available; if I made changes to Bar.cs , it reflected immediately (well, as usual, as usual, the background operation) in IntelliSense, when I edit Foo.cs , etc.

However, instead of directly compiling the None entry, say I want to copy it to the obj directory and then compile it from there. I can do this by changing the IndirectCompile target to this:

 <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> 

This causes IntelliSense to stop updating. The task is working on assembly, dependency analysis and incremental construction work, Visual Studio just stops automatically running it when the input file is saved.

So this leads to the title of the question: how does Visual Studio choose to launch goals or not for IntelliSense? The only official documentation I found was this , in particular the IntelliSense Design Time section. I am sure my code meets all of these criteria. What am I missing?

+8
visual-studio msbuild intellisense
source share
1 answer

After several days of experimenting and searching in the debugger, I think I found the answer, and, unfortunately, the answer is that this is impossible (at least not explicitly). I am sure there are ways to trick the system).

When the project is loaded, and when the project itself changes (files are added / deleted, assembly actions are changed, etc.), the IntelliSense assembly is performed ( csproj.dll!CLangCompiler::RunIntellisenseBuild ). This assembly will run tasks before and including the Csc task. Csc will not run normally, but instead will simply feed its inputs back to its host (Visual Studio).

From this point on, Visual Studio keeps track of the files that were specified as Sources for the Csc task. It will track these files for changes, and when they change, update IntelliSense. Therefore, in my example, if I manually edit Bar.g.cs , these changes will be raised. But the build tasks themselves will not be performed again until the project changes or the assembly is explicitly requested.

So this is disappointing, but not surprising, I think. This also explains what I've always been interested in - XAML code-based files usually have the Custom Tool MSBuild:Compile action, presumably for this reason.

I am going to mark this as an answer, but I would like to be told that I am wrong and that I missed something.

+6
source share

All Articles