Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# preprocessor directive for .net version when multi targeting

I’m currently migrating a project XY which is consumed by a net48 project and a new net8 project.

The project XY needs to implement a method that will only compile for net48 and another method which only compiles for net8.

To make that work, I’m using c# preprocessor commands as shown from Microsoft
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Unfortunately Visual Studio 2022 with latest update is showing the code now greyed out. I don’t understand this behavior, because the project itself is using multi targeting by using
net48;net8 in the csproj file.

So actually VS should be able to know that the project multi targets and the code is relevant and thus should not greyed out. Is there anything missing to make it work?

>Solution :

you need to select your current environment with the drop down menu directly located above your editor, like this:

If i would select net48, it’d look like this:

net48

Selecting net8.0 results in it being colored

net8.0

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading