MSBuild Condition for Design-Time and Compile-Time
I have the following MSBuild Snippet
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
directives already works.
How can this be achieved? I think it may be possible using some Condition for Design/Compile-Time or using Targets.4 Replies
This sounds like a very odd use case but if you need to do something in design time only follow https://github.com/dotnet/project-system/blob/main/docs/design-time-builds.md#determining-whether-a-target-is-running-in-a-design-time-build
GitHub
project-system/docs/design-time-builds.md at main · dotnet/project-...
The .NET Project System for Visual Studio. Contribute to dotnet/project-system development by creating an account on GitHub.
Can you state your goal? What are you trying to achieve?
Thanks. In the meantime I found an alternative:
Not sure which is better
I guess it is called Metaprogramming. I know there is Fody, but IL is not easy and I think debugging could get hard. But honestly I have never used it, so I may be wrong. Metalama is propriotary and Source Generators are limited.
Fody does il weaving and is frequently labeled under AOP, aspect oriented programming. Fody and postsharp both have weird licensing models
Some more advanced DI containers do offer some things that fody and postsharp ( and other weavers ) offer, but at a performance cost, sometimes a high performance cost.
Back in the day things like caching method results were pretty popular. For example:
In this scenario, read operations are cached, and continue to be cached until a write operation is executed, or the time expires.
Autofac supports things like this with some custom work.
I don't think that's what you're looking for though.