I have a .NET 9.0 console app that I build with Visual Studio 2022 on Windows and it has 2 launch profiles (Win and WSL2):
{
"profiles": {
"Windows": {
"commandName": "Project"
},
"WSL2": {
"commandName": "WSL2",
"distributionName": ""
}
}
}
I added .NET Framework 4.7.2 target (<TargetFrameworks>net9.0;net472</TargetFrameworks>
) and now "play" button looks as follows:
Is there a way to have two launch profiles only for 90 target (since 472 can only run on Windows). Are there some .csproj flags of something?
I have a .NET 9.0 console app that I build with Visual Studio 2022 on Windows and it has 2 launch profiles (Win and WSL2):
{
"profiles": {
"Windows": {
"commandName": "Project"
},
"WSL2": {
"commandName": "WSL2",
"distributionName": ""
}
}
}
I added .NET Framework 4.7.2 target (<TargetFrameworks>net9.0;net472</TargetFrameworks>
) and now "play" button looks as follows:
Is there a way to have two launch profiles only for .net90 target (since .net472 can only run on Windows). Are there some .csproj flags of something?
The launchSettings.json
doesn't support conditionalizing or tagging profiles for specific target frameworks.
The file is for development use only and is not deployed. Maybe the thinking was, that as a development file, it was okay to have "rough edges". I don't know.
With a multi-targeting project, all of the possible target frameworks could be in a built state and the project just needs to be able to be launched for any of the frameworks. Therefore, swapping or transforming the launchSettings.json
file on a build is not a good option.
WSL2
is a recognized "special" command name. Maybe the IDE should know that WSL2
can't be used with .NET Framework. It may be worth submitting a feature request for Visual Studio.
You can rename the profile.
e.g.
{
"profiles": {
"Windows": {
"commandName": "Project"
},
"WSL (use with net9.0)": {
"commandName": "WSL2",
"distributionName": ""
}
}
}
It's not pretty but when someone opens the "play" button drop-down, the name with the hint will be visible.
Is there a way to have two launch profiles only for .net90 target (since .net472 can only run on Windows)
I am afraid not. From looking at launchSettings.json,looks like there is no parameter like Framework
to specify this launch profile work for which version of frameworks.
But As a workaround, you can make that TFM conditional in your build based on current platform.
Add the following to your .csproj
file:
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' ">
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<TargetFrameworks>net9.0;net472</TargetFrameworks>
</PropertyGroup>