title: how to choose a particular dotnet core sdk when publishing dotnet app
body: <p>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.</p>
  <p>But, I recently installed <a href="https://visualstudio.microsoft.com/vs/preview/" rel="nofollow noreferrer">Visual Studio 2022 Preview</a>, and tried running <code>dotnet publish</code> command, it failed due to the preview sdk. See the console error message I'm getting below.</p>
  <p><img src="https://i.stack.imgur.com/I7rFM.png" alt="error message on publish, image link" /></p>
  <p>I have searched most of MSDN docs on how to specify dotnet version while publishing a dotnet app, but could not find a solution.</p>
  <p>I am using the powershell scripts below:</p>
  <pre><code>$version  =  &quot;6.12.0&quot;
  $product  =  &quot;CrystalERP&quot;
  $project  =  &quot;I:\CrystalRelease\crystal.erp\crystal.pos.cafe\Crystal.Pos.Cafe.csproj&quot;
  $output  =  &quot;I:\App&quot;
  $dotnet  =  &quot;C:\Program Files\dotnet\dotnet.exe&quot;
  $runtimes  = @(
  &quot;linux-x64&quot;
  )
  # clear previous releases
  
  Remove-Item &quot;$output\App*&quot;  -Recurse -Confirm:$true
  $runtimes  |  %{
  &amp;  $dotnet publish $project  -c release   -r $_  -o (&quot;{0}\{1}&quot;  -f $output,&quot;App&quot;)
  </code></pre>