我运行以下命令:
"C:\Program Files\dotnet\dotnet.exe" new console
我收到以下错误:
C:\Temp\myapp\myapp\myapp.csproj : warning NU1603: myapp depends on
Microsoft.NETCore.App (>= 2.1.0) but Microsoft.NETCore.App 2.1.0 was not found.
An approximate best match of Microsoft.NETCore.App 2.1.1 was resolved.
C:\Temp\myapp\myapp\myapp.csproj : error : The project was restored using
Microsoft.NETCore.App version 2.1.1, but with current settings, version 2.1.0
would be used instead. To resolve this issue, make sure the same settings
are used for restore and for subsequent operations such as build or publish.
Typically this issue can occur if the RuntimeIdentifier property is set
during build or publish but not during restore.
当我运行dotnet --info时,我得到以下信息:
.NET Core SDK (reflecting any global.json):
Version: 2.1.301
Commit: 59524873d6
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.301\
Host (useful for support):
Version: 2.1.1
Commit: 6985b9f684
.NET Core SDKs installed:
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.301 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.1 [C:\Program
Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.1 [C:\Program
Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.7 [C:\Program
Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [C:\Program
Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
最后在生成的myapp.csproj文件中:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
</Project>
我搜索了互联网,似乎很多人都遇到了同样的问题。我对正在发生的事情以及如何解决它感到好奇。我猜想我可以在CLI命令中更明确地说明我,但是我不确定要明确的方式和内容。
为了进一步使事情复杂化,我想我可以安装Visual Studio 2017,看看它如何构建Dotnet Core控制台应用程序。我认为它将安装所有必需的依赖项,并以一种可行的方式为该项目构建文件。
我很惊讶地看到csproj文件使用1.1作为目标框架:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
</Project>
我遇到了许多构建错误,包括以下内容:
Unable to find package Microsoft.NETCore.App with version (>= 1.1.2)
- Found 1 version(s) in Microsoft Visual Studio Offline Packages [
Nearest version: 1.0.0-rc2-3002702 ]
- Found 0 version(s) in MyDownloads ConsoleApp1
C:\Users\admin\Source\Repos\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj 1
更新
我重新安装了.NET Core SDK 2.1 x86和x64。我在Visual Studio 2017中创建了一个新的.NET控制台应用程序。它将无法构建。我收到以下错误:
Assets file not found project.assets.json. Run a nuget restore to create file.
运行nuget还原不会出错,但不会创建任何此类文件。
我从命令行构建了相同的项目,并创建了project.assets.json,并且该项目得以构建和运行。我的Visual Studio实例具有最新更新。在我的Visual Studio实例中损坏或丢失了什么?
答案 0 :(得分:0)
前几天,我遇到了这些问题。我只需将Build配置和CPU架构与发布时的架构相匹配即可解决此问题。
Microsoft在Documentation中也解决了与此相关的问题
他们指定您首先使用预期的配置进行构建,然后使用no-restore
选项进行发布
dotnet publish --no-restore -r win10-x64
修改 我认为您需要更新csproj文件
<TargetFramework>netcoreapp2.1.1</TargetFramework>
<PlatformTarget>AnyCPU</PlatformTarget>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
如果这不起作用,您可以尝试一些解决方案。
您可以创建一个global.json
来指定哪个SDK版本:
{
"sdk": { "version": "2.1.300" }
}
如果这不起作用,则可能有其他一些解决方案可能会有所帮助,您可以在以下位置找到它们 这个问题已在github上公开。