9

有人能解释这两个中的csproj文件的目的(VS2017):.NET核心RuntimeIdentifier VS TargetFramework

<TargetFramework>netstandard1.6</TargetFramework> 
<RuntimeIdentifier>win7</RuntimeIdentifier> 

我刚刚从VS2015迁移,现在因为它看起来我应该不能发布我的网络API只使用一个目标框架。另外我不能指定多个RID。 所有这些改变的事情让我感到沮丧。没有什么是从头开始的,应该一遍又一遍地克服某些事

我只想在Windows上开发我的web-api,在这里运行xUnit测试,然后部署web-api以在Linux(ubuntu)服务器上运行。 我应该把两个参数放在csproj中? 高度赞赏链接与良好的解释。

UPDATE1

我有引用.NET核心库的Web API。从VS2015迁移的所有东西。现在在根项目中我有 <TargetFrameworks>netcoreapp1.1;net461</TargetFrameworks>。当我通过VS2017发布我的错误:

C:\Program Files\dotnet\sdk\1.0.3\Sdks\Microsoft.NET.Sdk\buildCrossTargeting\Microsoft.NET.Sdk.targets(31,5): error : The 'Publish' target is not supported without specifying a target framework. The current project targets multiple frameworks, please specify the framework for the published application.

但我指定的目标框架,发布为netcoreapp1.1。好的。然后我按照以下建议更新我的csproj <PropertyGroup Condition="$(TargetFramework)'=='netcoreapp1.1'"> <RuntimeIdentifier>ubuntu.16.10-x64</RuntimeIdentifier> </PropertyGroup>。 但现在我甚至不能建立应用程序,得到错误:

5>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(92,5): error : Assets file '\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v1.1/ubuntu.16.10-x64'. Ensure you have restored this project for TargetFramework='netcoreapp1.1' and RuntimeIdentifier='ubuntu.16.10-x64'.

我只是想在窗口8.1/windows7的VS2017开发和部署到Ubuntu 16.10。 我做错了什么?

UPDATE2

我在溶液中具有8个项目。其中3个是xUnit测试。因此我们有5个项目。其中4个是类库,1个是我的网络应用程序。 所有4类库有这样的:

<TargetFrameworks>netstandard1.6;net461</TargetFrameworks>  
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' "> 
    <Reference Include="System" /> 
    <Reference Include="Microsoft.CSharp" /> 
</ItemGroup> 

我的web应用程序:

<TargetFrameworks>netcoreapp1.1;net461</TargetFrameworks> 
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' "> 
    <Reference Include="System" /> 
    <Reference Include="Microsoft.CSharp" /> 
    </ItemGroup> 

如何发布我的web应用程序?

回答

0

RID is short for Runtime IDentifier. RIDs are used to identify target operating systems where an application or asset (that is, assembly) will run. They look like this: "ubuntu.14.04-x64", "win7-x64", "osx.10.11-x64". For the packages with native dependencies, it will designate on which platforms the package can be restored.

docs

首先进入正确的RID从win7win7-x64win7-x86。接下来添加其他RID,如Ubuntu。例如:

<PropertyGroup> 
    <TargetFramework>netstandard1.6</TargetFramework> 
    <RuntimeIdentifier>win7-x64;ubuntu.16.10-x64</RuntimeIdentifier> 
</PropertyGroup> 

目标框架看起来不错。更多阅读docs

4

<TargetFramework>(或<TargetFrameworks>当你想有多个目标,如net451,一个或多个netstandard1.x等)。每<TargetFramework>/<TargetFrameworks>条目将创建一套程序集并位于bin\Debug\<targetframeworkid>的内部)。

当你想使用不同的库时,这很有用。NET Core(因为您使用的库只能用于完整的.NET Framework,比如4.5.1),或者从.NET Core中移除此功能,因为它不受支持。

它用于两个,建设和恢复的NuGet。即你不能在.NET的核心项目中使用net451只有库(netstandard 1.1例如 - 但你可以在一个net451项目中使用netstandard1.1)的另一边

<RuntimeIdentifier>/<RuntimeIdentifiers>用于主要的NuGet。它告诉NuGet你需要哪些软件包。例如,如果你想要定位Linux,Mac和Windows,某些程序集需要本地库(例如加密,在Windows上将使用CryptoAPI,但在Linux和Mac上则需要OpenSSL)。这包括非托管dll和* .so(Linux)文件。

<RuntimeIdentifiers>win7-x64;win-7x86;ubuntu.16.10-x64</RuntimeIdentifiers>将只的NuGet为Ubuntu还原WIN7包(x64和x86)版本和x64。这是必需的,因为当你在windows上工作时,你也需要下载这些本地库,所以你用dotnet publish来部署/打包它们。

这里有一个小抓虽然:当你在<TargetFramework><TargetFrameworks>一个完整的.NET框架的参考,则必须指定一个<RuntimeIdentifier>(单数,不是复数<RuntimeIdentifiers>),否则你会得到一个错误。

例如:

<PropertyGroup> 
    <TargetFrameworks>netstandard1.0;net451</TargetFrameworks> 
    <RuntimeIdentifiers>win7-x64;win-7x86;ubuntu.16.10-x64</RuntimeIdentifiers>  
</PropertyGroup> 

<!-- This entry will only be used for the .NET Framework 4.5.1 output --> 
<PropertyGroup Condition="'$(TargetFramework)' == 'net451'"> 
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier> 
</PropertyGroup> 
+0

' netstandard1.0; net451时使用的.Net标准他'是不必要的。你正在使用许多过时的做法 –

+0

我试过了,它不适合我。查看我在这个问题上的更新。 – Alezis

+0

@Alezis:阅读邮件;)当你有超过1个目标时,你必须告诉'dotnet publish'发布哪个版本。 https://docs.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-publish,即'dotnet publish --runtime ubuntu.16.10-x64'。在'netstandard1.0; net451'中''net451'已经过时了(因为'netstandard1.0'在.NET 4.5及更高版本上运行,但是如果你只使用1.3(.NET 4.6)中的特性,那么'netstandard1.3 ; net451'可以用于创建两个版本,请参阅https://docs.microsoft.com/en-us/dotnet/articles/standard/library – Tseng