问题描述
我有一个包含许多 .NET Core 项目的解决方案.我对所有项目进行了 NuGet 更新,现在当我尝试构建时出现以下错误(对于某些项目 - 不是全部):
找不到与以下目标运行时之一兼容的框架.NETCoreApp,Version=v1.0"的运行时目标:win10-x64、win81-x64、win8-x64、win7-x64".可能的原因:1.项目没有恢复或恢复失败-运行`dotnet restore`2. 项目在'runtimes'部分没有列出'win10-x64、win81-x64、win8-x64、win7-x64'之一.3. 您可能正在尝试发布不受支持的库.使用 `dotnet pack` 分发库.
似乎有帮助的是我在这里找到的帖子 找不到与目标运行时之一兼容的框架 .NETCoreApp=v1 的运行时目标
我在失败的项目中添加了以下内容:
运行时":{win10-x64":{}}
这似乎解决了问题.但我的问题是,为什么这种情况只发生在某些项目上?未发出错误的项目在其 project.json
文件中没有这样的运行时定义.
这个运行时定义究竟是什么意思?它如何影响我在 linux 或 mac 等其他操作系统上运行的能力?
runtimes
列出了我们的包支持的运行时.列出运行时对于独立部署是必要的.当部署具有自己的运行时时,它就是自包含的.
我们如何知道我们的部署是否是自包含的?dependencies
列出我们的包所依赖的包.这些依赖项分为三种类型.
build
包仅用于构建,不是部署的一部分platform
包将依赖于预安装的运行时default
两者都不是
如果我们的 "Microsoft.NETCore.App"
依赖项是 default
类型,那么它是自包含的,我们需要自带运行时.如果它是 platform
类型,那么它依赖于框架.
为什么这种情况只发生在某些项目上?
它只会发生在独立部署的项目中.如果您查看那些不需要 runtimes
属性的项目,您会发现它们要么依赖于类库,要么依赖于框架.
独立部署
框架":{netcoreapp1.0":{依赖关系":{Microsoft.NETCore.App":{版本":1.0.0"}}}},运行时":{win10-x64":{},osx.10.10-x64":{}}
依赖框架部署
框架":{netcoreapp1.0":{依赖关系":{Microsoft.NETCore.App":{"类型": "平台",版本":1.0.0"}}}}
类库
框架":{netstandard1.6":{}}
它如何影响我在 linux 或 mac 等其他操作系统上运行的能力?
它没有.Windows、Mac OS 和 Linux 都可以预先安装运行时或让应用程序自带运行时.
另见
- https://docs.microsoft.com/en-us/dotnet/articles/core/tools/project-json
- https://docs.microsoft.com/en-us/dotnet/articles/核心/部署/索引
- 这个链接特别值得一读,以区分独立部署和依赖框架的部署.
- https://docs.nuget.org/ndocs/schema/project.json莉>
I have a solution with many .NET Core projects. I did NuGet updates to all of the project and now when I try to build I get the following errors (for some of the projects - not all):
Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible with one of the target runtimes: 'win10-x64, win81-x64, win8-x64, win7-x64'. Possible causes:
1. The project has not been restored or restore failed - run `dotnet restore`
2. The project does not list one of 'win10-x64, win81-x64, win8-x64, win7-x64' in the 'runtimes' section.
3. You may be trying to publish a library, which is not supported. Use `dotnet pack` to distribute libraries.
What seemed to help was a post I found here Can not find runtime target for framework .NETCoreApp=v1 compatible with one of the target runtimes
I added the following to the failing projects:
"runtimes": {
"win10-x64": { }
}
That seemed to fix the issue. But my question is, why was this happening only on some projects? The projects that did not issue the error doesn't have such runtime definition in their project.json
file.
What exactly does this runtime definition means? how does it affect my ability to run on other os like linux or mac?
runtimes
lists the runtimes that our package supports. Listing runtimes is necessary for self-contained deployments. A deployment is self-contained when it brings its own runtime.
How do we know if our deployment is self-contained? dependencies
list the packages on which our package depends. These dependencies come in three types.
build
the package is for building only and is not part of the deploymentplatform
the package will depend on a pre-installed runtimedefault
neither of those
If our "Microsoft.NETCore.App"
dependency is of the default
type, then it is self-contained, and we will need to bring our own runtimes. If it is of the platform
type, then it is framework dependent.
It will only happen in projects that are self-contained deployments. If you look thru those projects that do not require a runtimes
property, you will find that they are either class libraries or framework dependent.
self-contained deployment
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0"
}
}
}
},
"runtimes": {
"win10-x64": {},
"osx.10.10-x64": {}
}
framework dependent deployment
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
}
}
}
class library
"frameworks": {
"netstandard1.6": {}
}
It doesn't. Windows, Mac OS, and Linux can all either have a runtime pre-installed or have the application bring its own runtime.
See also
- https://docs.microsoft.com/en-us/dotnet/articles/core/tools/project-json
- https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index
- This link in particular is worth reading to differentiate between self-contained and framework-dependency deployments.
- https://docs.nuget.org/ndocs/schema/project.json
这篇关于找不到与某些项目的目标运行时之一兼容的框架 .NETCoreApp=v1 的运行时目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!