Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

Dotnet Core 3.1 app won't run from Visual Studio Code

I have an app I recently upgraded from Dotnet Core 2.2.

It runs from the command line:

$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.101
 Commit:    d05174dc5a

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.10
 OS Platform: Linux
 RID:         ubuntu.20.10-x64
 Base Path:   /usr/share/dotnet/sdk/5.0.101/

Host (useful for support):
  Version: 5.0.1
  Commit:  b02e13abab

.NET SDKs installed:
  3.1.404 [/usr/share/dotnet/sdk]
  5.0.101 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
…
$ dotnet build
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  
  Bundler: Begin processing bundleconfig.json
  Bundler: Done processing bundleconfig.json
  uk.ac.sahfos.cpr.console.web -> /home/derek/MBA/uk.ac.sahfos.cpr.console.web/uk.ac.sahfos.cpr.console.web/bin/Debug/netcoreapp3.1/uk.ac.sahfos.cpr.console.web.dll
  uk.ac.sahfos.cpr.console.web -> /home/derek/MBA/uk.ac.sahfos.cpr.console.web/uk.ac.sahfos.cpr.console.web/bin/Debug/netcoreapp3.1/uk.ac.sahfos.cpr.console.web.Views.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.43
$ dotnet run
Content root path: /home/derek/MBA/uk.ac.sahfos.cpr.console.web/uk.ac.sahfos.cpr.console.web
Now listening on: http://localhost:49755
Application started. Press Ctrl+C to shut down.

but if I try to run it from inside VS Code I get:

Using launch settings from '/home/derek/MBA/uk.ac.sahfos.cpr.console.web/uk.ac.sahfos.cpr.console.web/Properties/launchSettings.json' [Profile '(Default)']...
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.All', version '2.2.0' was not found.
  - No frameworks were found.

You can resolve the problem by installing the specified framework and/or SDK.

Now, the launchsettings.json file contains no mention of the framework, and the .csproj has no reference to Microsoft.AspNetCore.All (or Microsoft.AspNetCore.App for that matter):

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <PropertyGroup>
    <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
    <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="BuildBundlerMinifier" Version="2.6.362"/>
    <PackageReference Include="Grid.AspNetCore.Mvc" Version="1.0.0"/>
    <PackageReference Include="HtmlAgilityPack" Version="1.11.16"/>
    <PackageReference Include="Humanizer" Version="2.6.2"/>Microsoft.AspNetCore.All
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.4"/>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="3.1.4"/>
    <PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="2.3.8"/>
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="3.1.4"/>
    <PackageReference Include="EFCore.NamingConventions" Version="1.1.0"/>
    <PackageReference Include="GeoAPI.Core" Version="1.7.5"/>
    <PackageReference Include="System.Composition" Version="1.0.31"/>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.11"/>
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4"/>
  </ItemGroup>
</Project>

So, where is it picking up this requirement for 2.2?

question from:https://stackoverflow.com/questions/65830571/dotnet-core-3-1-app-wont-run-from-visual-studio-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Naturally, immediately after posting, I found the answer.

Despite the message:

Using launch settings from '/home/derek/MBA/uk.ac.sahfos.cpr.console.web/uk.ac.sahfos.cpr.console.web/Properties/launchSettings.json' [Profile '(Default)']...

launchSettings.json is irrelevant. It's the launch.json file that has a hard-coded path to the framework and warns:

// If you have changed target frameworks, make sure to update the program path.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...