Reputation: 1717
I have many C# script source files in the project tree marked as Build Action: None
The problem is: if the source file is marked as Build Action: None
then Go To Declaration
, Go To Implementation
and other navigation and refactoring functions of Visual Studio and Resharper doesn't work anymore.
The script files are eventually compiled by the CSharpCodeProvider
once the app is running and generally behave 100% the same as if they were in the actual code base (the original executable assembly).
The difference here is that the source files are not compiled by MSBuild, but by the app itself.
How can I force Visual Studio/build process to analyze the files (as if they were going to be compiled) without including them into final executable assembly?
Upvotes: 2
Views: 764
Reputation: 14164
If you edit the main project file (.csproj
) and add an AfterBuild
target, you can invoke any custom action on post build. The following example calls compile.exe for all Build Action=None
items in the project with extension of .proj
.
<Target Name="AfterBuild">
<ItemGroup>
<Scripts Include="@(None)" Condition="'%(Extension)' == '.proj'" />
</ItemGroup>
<Message Text="Scripts files: @(Scripts)" Importance="high" />
<Exec Command="Compile.exe %22%(Scripts.FullPath)%22"
WorkingDirectory="$(MSBuildProjectDirectory)"
Condition="'@(Scripts)' != ''" />
</Target>
Upvotes: 1
Reputation: 11840
One possible option is to have different build configurations, with different settings for the files in question.
You can have a development configuration, where the files are set to 'compile', and a deployment configuration, where they're set to 'none'.
That way, you'll get nice Intellisense when working on your code, and no compilation happening when you flip to 'deployment' configuration before you build.
Upvotes: 0