无法找到框架的运行时目标。netcoreapp =v1与一个目标运行时兼容吗?

时间:2022-07-17 17:07:58

I am trying to migrate an Asp.Net Core RC1 project to RC2 and have been following this documentation and have also followed the instructions for DNX migration to .NET CLI.

我正在尝试迁移一个Asp。Net核心RC1项目到RC2,并一直遵循这个文档,并遵循了DNX迁移到。Net CLI的说明。

I am getting the following error when I try dotnet run:

当我尝试dotnet运行时,我得到如下错误:

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:

无法找到框架的运行时目标。NETCoreAPP, Version=v1.0'兼容一个目标运行时:'win10-x64, win81-x64, win8-x64, win7-x64'。可能的原因:

  1. The project has not been restored or restore failed -run 'dotnet restore'
  2. 项目没有恢复或恢复失败的“dotnet恢复”
  3. The project does not list one of 'win10-x64, win81-x64, win7-x64' in the 'runtimes'
  4. 该项目没有在“运行时”中列出“win10-x64, win81-x64, win7-x64”。

I have run dotnet restore and it seems to have completed successfully.

我已经运行了dotnet恢复,它似乎已经成功完成了。

I have updated all the relevant packages to RC2.

我已经将所有相关的包更新到RC2。

10 个解决方案

#1


290  

I should have done exactly what the error message said. When migrating from RC1, I did not realise that I had to specify a runtimes section in my project.json file.

我应该准确地完成错误信息。从RC1迁移时,我没有意识到我必须在项目中指定一个运行时部分。json文件。

In my project.json I added the following section:

在我的项目。我添加了以下部分:

"runtimes": {
    "win10-x64": { }
  }

And I was good to go.

我很高兴去。


Update 27 February 2017

2017年2月27日更新

New project templates in Visual Studio 2017 RC no longer require run times to be specified (in project.json or .csproj) in advance if you choose to deploy your app as a Framework Dependent Deployment (FDD).

Visual Studio 2017 RC中新的项目模板不再需要指定运行时间(在项目中)。如果您选择将您的应用程序部署为依赖于框架的部署(FDD),那么可以提前使用json或.csproj。

If, however, you choose to deploy your app using Self-contained Deployment (SCD), then you will need to specify all the run times you want your app to run on in advance in your .csproj file.

但是,如果您选择使用独立部署(SCD)部署应用程序,那么您需要指定所有运行时间,您希望应用程序在.csproj文件中提前运行。

Below is an example of a .csproj file for an app that uses the SCD deployment method:

下面是一个使用SCD部署方法的应用程序的.csproj文件示例:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.0</TargetFramework>
    <VersionPrefix>1.0.0</VersionPrefix>
    <DebugType>Portable</DebugType>
    <RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
  </ItemGroup>
</Project>

Please see this link for more information, which includes a thorough description of both types of deployment options, as well as their benefits and disadvantages.

请参见此链接以获取更多信息,其中包括对这两种部署选项的详细描述,以及它们的优缺点。

#2


76  

I received this error after updating VS2015 core template to 1.0.1. It was because I have a PCL that targets netstandard 1.4 if you don't want to have to specify each runtime, Just change the dependency markup for Microsoft.NETCore.App to this:

在更新VS2015 core template到1.0.1之后,我收到了这个错误。这是因为我有一个PCL,目标是netstandard 1.4,如果您不想指定每个运行时,只需更改Microsoft.NETCore的依赖项标记。应用:

"Microsoft.NETCore.App": {
 "type": "platform",
 "version": "1.0.1"
}

#3


34  

in project.json I changed this (added type):

在项目。我改变了这个(添加的类型):

//"Microsoft.NETCore.App": "1.1.0",
"Microsoft.NETCore.App": { "version": "1.1.0", "type": "platform" },

Now I can build again :-)

现在我可以重新构建:-)

update: now I can build again but not "run" the website.

更新:现在我可以重新构建但不是“运行”网站。

You need to make sure you have the runtime and sdk also:

你需要确保你有运行时和sdk

*) Visual Studio tools include .NET Core 1.0.1. To add .NET Core 1.1 support you need to also install the .NET Core 1.1 runtime.

*)Visual Studio工具包括. net核心1.0.1。要添加。net核心1.1支持,您还需要安装. net核心1.1运行时。

https://www.microsoft.com/net/download/core#/current

https://www.microsoft.com/net/download/core /电流

#4


20  

I received this error because I used the incredibly broken NuGet Package Manager in Visual Studio 2015 to update my project.json dependencies. It turned this:

我收到了这个错误,因为我在Visual Studio 2015中使用了令人难以置信的NuGet包管理器来更新我的项目。json依赖性。结果:

"frameworks": {
  "netcoreapp1.0": {
    "dependencies": {
      "Microsoft.NETCore.App": {
        "type": "platform",
        "version": "1.0.1"
      } 
    }
  }
}

into this:

到这个:

"dependencies": {
  "Microsoft.NETCore.App": "1.1.0"
},
"frameworks": {
  "netcoreapp1.0": {}
}

Bye bye, platform definition!

拜拜,平台定义!

#5


14  

If you read these two links:

如果你读了这两个链接:

First, https://docs.microsoft.com/en-us/dotnet/articles/core/tutorials/using-with-xplat-cli

首先,https://docs.microsoft.com/en-us/dotnet/articles/core/tutorials/using-with-xplat-cli

and

second, https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog

第二,https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog

You will see that you can build a completely portable version using the following snippet in the dependencies root element in project.json. There is no need to specify runtimes as this is a CORE level runtime which should be platform agnostic, or known as "Framework dependent"

您将看到,您可以在project.json中的依赖根元素中使用以下代码片段构建一个完全可移植的版本。没有必要指定运行时,因为这是一个核心级别的运行时,应该是平台无关的,或者称为“框架依赖”

"Microsoft.NETCore.App": {
    "type": "platform",
    "version": "1.0.1"
}

or you can build for multiple targeted platforms ("self contained applications") by removing the type: platform element like this:

或者您可以通过删除类型:平台元素来构建多个目标平台(“自包含应用程序”):

Add this to the dependencies root element in project.json

将此添加到project.json中的依赖项根元素。

"Microsoft.NETCore.App": {
    "version": "1.0.1"
}

and add this as a new root level element

并将其添加为新的根级别元素。

"runtimes": {
    "win10-x64": {},  /* one or more RIDs */
    "osx.10.10-x64": {}
  },

Multiple targeted requires that you supply platform names known as ".NET Core Runtime IDentifiers (RID)" A list of these can be found at the second link above. It includes many flavors of Windows, Linux and OS X.

多个目标要求您提供名为“的平台名称”。NET核心运行时标识符(RID)可以在上面的第二个链接中找到它们的列表。它包含了Windows、Linux和OS X的多种风格。

For a good overview of the various deployment optins, you can read this page as well:

为了更好地概述各种部署optins,您还可以阅读这一页:

https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index

https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index

From the above link:

从上面的链接:

You can create two types of deployments for .NET Core applications:

您可以为.NET核心应用程序创建两种类型的部署:

Framework-dependent deployment

Framework-dependent部署

As the name implies, framework-dependent deployment (FDD) relies on a shared system-wide version of .NET Core to be present on the target system. Because .NET Core is already present, your app is also portable between installations of .NET Core. Your app contains only its own code and any third-party dependencies that are outside of the .NET Core libraries. FDDs contain .dll files that can be launched by using the dotnet utility from the command line. For example, dotnet app.dll runs an application named app.

顾名思义,框架依赖的部署(FDD)依赖于一个共享的系统版本的. net核心,以呈现在目标系统上。因为。net核心已经存在,你的应用也可以在。net核心的安装之间移动。您的应用程序只包含它自己的代码和在. net核心库之外的任何第三方依赖项。FDDs包含.dll文件,可以通过使用命令行中的dotnet实用程序启动。例如,dotnet app.dll运行一个名为app的应用程序。

Self-contained deployment

独立的部署

Unlike FDD, a self-contained deployment (SCD) does not rely on any shared components to be present on the target system. All components, including both .NET Core libraries and the .NET Core runtime, are included with the application and are isolated from other .NET Core applications. SCDs include an executable (such as app.exe on Windows platforms for an application named app), which is a renamed version of the platform-specific .NET Core host, and a .dll file (such as app.dll), which is the actual application.

与FDD不同,独立部署(SCD)不依赖于在目标系统上存在的任何共享组件。所有组件,包括。net核心库和。net核心运行时,都包含在应用程序中,并与其他。net核心应用程序隔离。SCDs包括一个可执行文件(如应用程序的Windows平台上的app.exe),它是特定于平台的. net核心主机的重命名版本,以及一个.dll文件(如app.dll),这是实际的应用程序。

#6


9  

In my case I had just updated all the nuget packages to their latest versions and nuget changed my 'Microsoft.NETCore.App' package reference to the following:

在我的例子中,我刚刚更新了所有的nuget包,它们的最新版本和nuget改变了我的“Microsoft.NETCore”。应用程序包引用如下:

"Microsoft.NETCore.App": "1.1.0"

I changed it back to the following form and everything worked fine:

我把它改成了下面的表格,一切都很好:

"Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    }

Good bye 3 hours of my life....

再见我生活的3小时....

#7


4  

if you execute a dotnet new and look at the output project json, you will see that the monikers have changed.

如果您执行一个dotnet new并查看输出项目json,您会发现这个名字已经发生了变化。

Make the changes to your project.json as follows:

对项目进行更改。json如下:

"dependencies": {},
   "frameworks": {
     "netcoreapp1.0": {
        "dependencies": {
         "Microsoft.NETCore.App": {
         "type": "platform",
         "version": "1.0.1"
         }
    },
      "imports": "dnxcore50"
    }
  }

#8


0  

I found one useful link from comment by svick under following page: https://github.com/dotnet/cli/issues/2442

我在以下页面找到了svick评论的一个有用链接:https://github.com/dotnet/cli/es/2442。

#9


0  

I found you need the following in project.json. Here is what was required to fix my error:

我发现在project.json中需要以下内容。以下是修正我的错误所需要的:

Dependencies

依赖关系

"dependencies": {
   "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
   },
}

Frameworks

框架

"frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

Runtime

运行时

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

You might want to add runtimes if you plan on publishing to IIS. Please see something as follows:

如果您打算将其发布到IIS,您可能需要添加运行时。请看以下内容:

 "runtimes": {
    "win10-x64": {}
  },

Here is a general tip that has worked well for me. When my stuff breaks, I sometimes create a default ASP.NET Core application either the website or empty web api to look at the dependencies in project.json and elsewhere. You can often catch a lot of things that way. The answers above are spot on, but I thought I would write this here in case someone wanted to separate the logic out more in the general template format that ASP.NET Core uses.

这是一个对我来说很有效的建议。当我的东西中断时,我有时会创建一个默认的ASP。NET核心应用程序,要么是网站,要么是空的web api,以查看项目中的依赖项。json和其他地方。你可以经常用那种方式抓住很多东西。上面的答案是正确的,但是我想我应该把它写在这里,以防有人想把逻辑更多地用在通用模板格式中。网络核心使用。

#10


0  

In Windows 7 with VS 2015, the soluiton after updating to netcore 1.1.2 was changing the project.json file as following:

在VS 2015的Windows 7中,更新到netcore 1.1.2后的解决方案正在改变项目。json文件如下:

{
"version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.NETCore.App": "1.1.2"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"    //This line must disappear
    }
  },

  "runtimes": {                 //
    "win7-x64": {}              //Add this lines
  }                             //
}

After changing this the dependencies will update and viola.

更改后,依赖项将更新和中提琴。

#1


290  

I should have done exactly what the error message said. When migrating from RC1, I did not realise that I had to specify a runtimes section in my project.json file.

我应该准确地完成错误信息。从RC1迁移时,我没有意识到我必须在项目中指定一个运行时部分。json文件。

In my project.json I added the following section:

在我的项目。我添加了以下部分:

"runtimes": {
    "win10-x64": { }
  }

And I was good to go.

我很高兴去。


Update 27 February 2017

2017年2月27日更新

New project templates in Visual Studio 2017 RC no longer require run times to be specified (in project.json or .csproj) in advance if you choose to deploy your app as a Framework Dependent Deployment (FDD).

Visual Studio 2017 RC中新的项目模板不再需要指定运行时间(在项目中)。如果您选择将您的应用程序部署为依赖于框架的部署(FDD),那么可以提前使用json或.csproj。

If, however, you choose to deploy your app using Self-contained Deployment (SCD), then you will need to specify all the run times you want your app to run on in advance in your .csproj file.

但是,如果您选择使用独立部署(SCD)部署应用程序,那么您需要指定所有运行时间,您希望应用程序在.csproj文件中提前运行。

Below is an example of a .csproj file for an app that uses the SCD deployment method:

下面是一个使用SCD部署方法的应用程序的.csproj文件示例:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.0</TargetFramework>
    <VersionPrefix>1.0.0</VersionPrefix>
    <DebugType>Portable</DebugType>
    <RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
  </ItemGroup>
</Project>

Please see this link for more information, which includes a thorough description of both types of deployment options, as well as their benefits and disadvantages.

请参见此链接以获取更多信息,其中包括对这两种部署选项的详细描述,以及它们的优缺点。

#2


76  

I received this error after updating VS2015 core template to 1.0.1. It was because I have a PCL that targets netstandard 1.4 if you don't want to have to specify each runtime, Just change the dependency markup for Microsoft.NETCore.App to this:

在更新VS2015 core template到1.0.1之后,我收到了这个错误。这是因为我有一个PCL,目标是netstandard 1.4,如果您不想指定每个运行时,只需更改Microsoft.NETCore的依赖项标记。应用:

"Microsoft.NETCore.App": {
 "type": "platform",
 "version": "1.0.1"
}

#3


34  

in project.json I changed this (added type):

在项目。我改变了这个(添加的类型):

//"Microsoft.NETCore.App": "1.1.0",
"Microsoft.NETCore.App": { "version": "1.1.0", "type": "platform" },

Now I can build again :-)

现在我可以重新构建:-)

update: now I can build again but not "run" the website.

更新:现在我可以重新构建但不是“运行”网站。

You need to make sure you have the runtime and sdk also:

你需要确保你有运行时和sdk

*) Visual Studio tools include .NET Core 1.0.1. To add .NET Core 1.1 support you need to also install the .NET Core 1.1 runtime.

*)Visual Studio工具包括. net核心1.0.1。要添加。net核心1.1支持,您还需要安装. net核心1.1运行时。

https://www.microsoft.com/net/download/core#/current

https://www.microsoft.com/net/download/core /电流

#4


20  

I received this error because I used the incredibly broken NuGet Package Manager in Visual Studio 2015 to update my project.json dependencies. It turned this:

我收到了这个错误,因为我在Visual Studio 2015中使用了令人难以置信的NuGet包管理器来更新我的项目。json依赖性。结果:

"frameworks": {
  "netcoreapp1.0": {
    "dependencies": {
      "Microsoft.NETCore.App": {
        "type": "platform",
        "version": "1.0.1"
      } 
    }
  }
}

into this:

到这个:

"dependencies": {
  "Microsoft.NETCore.App": "1.1.0"
},
"frameworks": {
  "netcoreapp1.0": {}
}

Bye bye, platform definition!

拜拜,平台定义!

#5


14  

If you read these two links:

如果你读了这两个链接:

First, https://docs.microsoft.com/en-us/dotnet/articles/core/tutorials/using-with-xplat-cli

首先,https://docs.microsoft.com/en-us/dotnet/articles/core/tutorials/using-with-xplat-cli

and

second, https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog

第二,https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog

You will see that you can build a completely portable version using the following snippet in the dependencies root element in project.json. There is no need to specify runtimes as this is a CORE level runtime which should be platform agnostic, or known as "Framework dependent"

您将看到,您可以在project.json中的依赖根元素中使用以下代码片段构建一个完全可移植的版本。没有必要指定运行时,因为这是一个核心级别的运行时,应该是平台无关的,或者称为“框架依赖”

"Microsoft.NETCore.App": {
    "type": "platform",
    "version": "1.0.1"
}

or you can build for multiple targeted platforms ("self contained applications") by removing the type: platform element like this:

或者您可以通过删除类型:平台元素来构建多个目标平台(“自包含应用程序”):

Add this to the dependencies root element in project.json

将此添加到project.json中的依赖项根元素。

"Microsoft.NETCore.App": {
    "version": "1.0.1"
}

and add this as a new root level element

并将其添加为新的根级别元素。

"runtimes": {
    "win10-x64": {},  /* one or more RIDs */
    "osx.10.10-x64": {}
  },

Multiple targeted requires that you supply platform names known as ".NET Core Runtime IDentifiers (RID)" A list of these can be found at the second link above. It includes many flavors of Windows, Linux and OS X.

多个目标要求您提供名为“的平台名称”。NET核心运行时标识符(RID)可以在上面的第二个链接中找到它们的列表。它包含了Windows、Linux和OS X的多种风格。

For a good overview of the various deployment optins, you can read this page as well:

为了更好地概述各种部署optins,您还可以阅读这一页:

https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index

https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index

From the above link:

从上面的链接:

You can create two types of deployments for .NET Core applications:

您可以为.NET核心应用程序创建两种类型的部署:

Framework-dependent deployment

Framework-dependent部署

As the name implies, framework-dependent deployment (FDD) relies on a shared system-wide version of .NET Core to be present on the target system. Because .NET Core is already present, your app is also portable between installations of .NET Core. Your app contains only its own code and any third-party dependencies that are outside of the .NET Core libraries. FDDs contain .dll files that can be launched by using the dotnet utility from the command line. For example, dotnet app.dll runs an application named app.

顾名思义,框架依赖的部署(FDD)依赖于一个共享的系统版本的. net核心,以呈现在目标系统上。因为。net核心已经存在,你的应用也可以在。net核心的安装之间移动。您的应用程序只包含它自己的代码和在. net核心库之外的任何第三方依赖项。FDDs包含.dll文件,可以通过使用命令行中的dotnet实用程序启动。例如,dotnet app.dll运行一个名为app的应用程序。

Self-contained deployment

独立的部署

Unlike FDD, a self-contained deployment (SCD) does not rely on any shared components to be present on the target system. All components, including both .NET Core libraries and the .NET Core runtime, are included with the application and are isolated from other .NET Core applications. SCDs include an executable (such as app.exe on Windows platforms for an application named app), which is a renamed version of the platform-specific .NET Core host, and a .dll file (such as app.dll), which is the actual application.

与FDD不同,独立部署(SCD)不依赖于在目标系统上存在的任何共享组件。所有组件,包括。net核心库和。net核心运行时,都包含在应用程序中,并与其他。net核心应用程序隔离。SCDs包括一个可执行文件(如应用程序的Windows平台上的app.exe),它是特定于平台的. net核心主机的重命名版本,以及一个.dll文件(如app.dll),这是实际的应用程序。

#6


9  

In my case I had just updated all the nuget packages to their latest versions and nuget changed my 'Microsoft.NETCore.App' package reference to the following:

在我的例子中,我刚刚更新了所有的nuget包,它们的最新版本和nuget改变了我的“Microsoft.NETCore”。应用程序包引用如下:

"Microsoft.NETCore.App": "1.1.0"

I changed it back to the following form and everything worked fine:

我把它改成了下面的表格,一切都很好:

"Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    }

Good bye 3 hours of my life....

再见我生活的3小时....

#7


4  

if you execute a dotnet new and look at the output project json, you will see that the monikers have changed.

如果您执行一个dotnet new并查看输出项目json,您会发现这个名字已经发生了变化。

Make the changes to your project.json as follows:

对项目进行更改。json如下:

"dependencies": {},
   "frameworks": {
     "netcoreapp1.0": {
        "dependencies": {
         "Microsoft.NETCore.App": {
         "type": "platform",
         "version": "1.0.1"
         }
    },
      "imports": "dnxcore50"
    }
  }

#8


0  

I found one useful link from comment by svick under following page: https://github.com/dotnet/cli/issues/2442

我在以下页面找到了svick评论的一个有用链接:https://github.com/dotnet/cli/es/2442。

#9


0  

I found you need the following in project.json. Here is what was required to fix my error:

我发现在project.json中需要以下内容。以下是修正我的错误所需要的:

Dependencies

依赖关系

"dependencies": {
   "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
   },
}

Frameworks

框架

"frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

Runtime

运行时

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

You might want to add runtimes if you plan on publishing to IIS. Please see something as follows:

如果您打算将其发布到IIS,您可能需要添加运行时。请看以下内容:

 "runtimes": {
    "win10-x64": {}
  },

Here is a general tip that has worked well for me. When my stuff breaks, I sometimes create a default ASP.NET Core application either the website or empty web api to look at the dependencies in project.json and elsewhere. You can often catch a lot of things that way. The answers above are spot on, but I thought I would write this here in case someone wanted to separate the logic out more in the general template format that ASP.NET Core uses.

这是一个对我来说很有效的建议。当我的东西中断时,我有时会创建一个默认的ASP。NET核心应用程序,要么是网站,要么是空的web api,以查看项目中的依赖项。json和其他地方。你可以经常用那种方式抓住很多东西。上面的答案是正确的,但是我想我应该把它写在这里,以防有人想把逻辑更多地用在通用模板格式中。网络核心使用。

#10


0  

In Windows 7 with VS 2015, the soluiton after updating to netcore 1.1.2 was changing the project.json file as following:

在VS 2015的Windows 7中,更新到netcore 1.1.2后的解决方案正在改变项目。json文件如下:

{
"version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.NETCore.App": "1.1.2"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"    //This line must disappear
    }
  },

  "runtimes": {                 //
    "win7-x64": {}              //Add this lines
  }                             //
}

After changing this the dependencies will update and viola.

更改后,依赖项将更新和中提琴。