Dotnet run command doesn't work in Microsoft Sandbox

Jacob Højland Troelsen 20 Reputation points
2023-10-04T07:39:18.5266667+00:00

I am encountering an error while trying to run an app using the command 'dotnet run' as part of the Exercise - Use shared access signatures to delegate access to Azure Storage. The error says that the command could not be loaded and that a compatible .NET SDK was not found. I would appreciate any help in fixing this issue. Here is the error:

The command could not be loaded, possibly because:
  * You intended to execute a .NET application:
      The application 'run' does not exist.
  * You intended to execute a .NET SDK command:
      A compatible .NET SDK was not found.
Requested SDK version: 6.0.300
global.json file: /home/jacob/sas/global.json
Installed SDKs:
7.0.401 [/usr/share/dotnet/sdk]
Install the [6.0.300] .NET SDK or update [/home/jacob/sas/global.json] to match an installed SDK.
Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found
Azure Training
Azure Training
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Training: Instruction to develop new skills.
1,668 questions
0 comments No comments
{count} votes

Accepted answer
  1. Joseph Gibbs 90 Reputation points
    2023-10-04T08:35:16.38+00:00

    Hi Jacob,

    This is a bug in which the example code provided does not reference the actual installed SDK in the sandbox. Others and I noticed this as well when going through the learn modules and opened pull requests via GitHub.

    You'll need to edit global.json and patient-records.csproj. Feel free to use my pull request edit as a reference, but you'll want to set version in global.json to 7.0.401 in this case. 7.0.400 would also work as in my code, since this will roll forward to the latest installed minor version of the SDK.

    code ~/sas/global.json
    
    {
      "sdk": {
        "version": "7.0.401",
        "rollForward": "latestMinor"
      }
    }
    

    You'll also need to set the target framework to netcoreapp7.0 in patient-records.csproj. I also updated some other package reference versions in my case.

    code ~/sas/patient-records.csproj
    
    <?xml version="1.0" encoding="utf-8"?>
    <Project Sdk="Microsoft.NET.Sdk.Web">
      <PropertyGroup>
        <TargetFramework>netcoreapp7.0</TargetFramework>
        <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
        <RootNamespace>patientrecords</RootNamespace>
      </PropertyGroup>
      <ItemGroup>
        <PackageReference Include="Azure.Identity" Version="1.10.0" />
        <PackageReference Include="Azure.Storage.Blobs" Version="12.17.0" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.10" />
      </ItemGroup>
    </Project>
    

    I wouldn't be surprised if this needs to be changed again once .NET 8 is out of preview and possibly installed in the MS Learn sandboxes, but this should run after you update the referenced SDK version and target framework.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.