.netvisual-studio.net-6.0visual-studio-2022

How to properly target Linux as Target OS in VisualStudio 2022?


I am developing a .NET6.0 console app in VisualStudio 2022. The app will run on Linux.

In project Properties/Application/General, there is a "Target OS" setting. The drop down list allows me to choose from the following OS':

enter image description here

There is no Linux option, so I set this to (None) and when publish the app with "Target runtime" in "Publish profile" as 'linux-x64':

enter image description here

...it will run on Linux no problem.

But since there is no Linux option in the drop down menu in application settings, hence my questions:

  1. Is this the case for everyone, or am I lacking something in my VS installation?
  2. Does this setting affect the builds at all - since (None) doesn't seem to have any effect and the settings in publish profile seem to have the last word anyway.
  3. Is (None) setting fine if I want to publish for Linux, or will there be any ramifications?

Solution

  • None is correct for the Target OS since it has nothing extra. All of the other target frameworks contain platform-specific features. (Like WPF related Namespaces are under Windows). Another way to look at it is None=Everywhere

    What you might be interested in is setting the RuntimeIdentifier or RuntimeIdentifiers in your .csproj.

    For your case the following is probably what you'll want:

    <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
    

    With this set, the compiler/Visual Studio will warn you about the usage of methods not available on one of the specified platforms. Console has some that only work on Windows.

    More about RIDs here.