© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•14mo ago•
6 replies
David

MSBuild Condition for Design-Time and Compile-Time

I have the following MSBuild Snippet
    <ItemGroup>
        <Compile Remove="Program.cs"></Compile>
        <Compile Update="Program2.cs"></Compile>
        <None Visible="true" Include="Program.cs"></None>
    </ItemGroup>
    <ItemGroup>
        <Compile Remove="Program.cs"></Compile>
        <Compile Update="Program2.cs"></Compile>
        <None Visible="true" Include="Program.cs"></None>
    </ItemGroup>

Program2.cs represents Generated Code.
I want to achieve this:
* Do not compile Program.cs
* Enable Intelisense on Program.cs. In general treat it as if it was Compiled during design time
* Program2.cs should not be referenceable from other Code.

Redirecting the Debugger from Program2.cs to Program.cs using
#line
#line
directives already works.

How can this be achieved? I think it may be possible using some Condition for Design/Compile-Time or using Targets.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

When Intellisense run MSBuild Compile on the project? [Answered]
C#CC# / help
4y ago
Visual code studio and msbuild
C#CC# / help
2y ago
✅ Modern T4 Replacement for Design Time Codegen
C#CC# / help
11mo ago
MSBuild tasks, external dependencies and NuGet
C#CC# / help
2y ago