0

I have an application targeting dotnet 5.0.* which I publish using the command line. I've used Visual Studio 2019 with dotnet 5.0.* SDK installed and publishing worked fine on that.

But, I recently installed Visual Studio 2022 Preview, and tried running dotnet publish command, it failed due to the preview sdk. See the console error message I'm getting below.

error message on publish, image link

I have searched most of MSDN docs on how to specify dotnet version while publishing a dotnet app, but could not find a solution.

I am using the powershell scripts below:

$version  =  "6.12.0"
$product  =  "CrystalERP"
$project  =  "I:\CrystalRelease\crystal.erp\crystal.pos.cafe\Crystal.Pos.Cafe.csproj"
$output  =  "I:\App"
$dotnet  =  "C:\Program Files\dotnet\dotnet.exe"
$runtimes  = @(
"linux-x64"
)
# clear previous releases

Remove-Item "$output\App*"  -Recurse -Confirm:$true
$runtimes  |  %{
&  $dotnet publish $project  -c release   -r $_  -o ("{0}\{1}"  -f $output,"App")
Timothy Macharia
  • 2,641
  • 1
  • 20
  • 27
Sandip124
  • 3
  • 5

2 Answers2

1

You can set a common version to be used across all your application development to be consistent with dependency and tools.

Command:

dotnet new globaljson --sdk-version <installed sdk versions of .NET>

It will create "global.json" file.

To check what versions are installed ( in case you are not aware ) use -

dotnet sdk check

output: enter image description here

After getting version details you can set which one to use based on your requirements

e.g.

dotnet new globaljson --sdk-version 6.0.306

Generated file location:

"C:\Users\username\global.json"
WitVault
  • 23,445
  • 19
  • 103
  • 133
0

Building/publishing is a feature of the SDK.

You can use dotnet --list SDKs to see all the SDKs installed on your machine.

Then you should use global.json to specify the SDK that should be used to build your application.

{
  "sdk": {
    "version": "5.0.100",
  }
}

See global.json docs for more details.

omajid
  • 14,165
  • 4
  • 47
  • 64