使用NET Standard 1.X的Nuget包

时间:2016-05-21 08:16:41

标签: c# asp.net portable-class-library .net-core .net-core-rc2

作为一个概念验证,我想创建一个由单个程序集组成的Nuget包。此程序集使用全新的 .NET Standard 1.X配置文件进行编译。我的想法是不仅可以使用.NET Core,还可以使用.NET 4.6.1(完整框架),甚至是旧版本,但我不知道如何使用。

目前,我创建了一个nuspec文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>

    <id>MyPackage</id>
    <description>MyPackage</description>

    <version>X.X.X.X</version>
    <authors>JMN</authors>
    <owners>JMN</owners>
    <licenseUrl>http://opensource.org/licenses/Apache-2.0</licenseUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>

  </metadata>

  <files>
    <file src="bin\Release\MyLib.dll" target="lib\netstandard1.X\MyLib.dll" />
  </files>

</package>

问题是,在将程序包添加到面向.NET Framework 4.6.1的项目时,它会显示此消息(输出窗口)

  

无法安装包&#39; MyLib X.X.X.X&#39;。您正在尝试安装   这个包成了一个目标项目   &#39; .NETFramework,Version = v4.6.1&#39;,但该包不包含任何内容   程序集引用或与之兼容的内容文件   框架。有关更多信息,请与软件包作者联系。

如何使我的nuget包可用于两个框架(至少.NET Standard 1.X和.NET Framework 4.6.1)。

1 个答案:

答案 0 :(得分:0)

你根本不需要你自己的nuspec。

只需创建一个RC 2 project.json,然后使用- (void)doStuff { @weakify(self); // __weak __typeof__(self) self_weak_ = self; [self doSomeAsyncStuff:^{ @strongify(self); // __strong __typeof__(self) self = self_weak_; // now you don't run the risk of self being deallocated // whilst doing stuff inside this block // But there's a chance that self was already deallocated, so // you could want to check if self == nil [self doSomeAwesomeStuff]; [self doSomeOtherAsyncStuff:^{ @strongify(self); // __strong __typeof__(self) self = self_weak_; // now you don't run the risk of self being deallocated // whilst doing stuff inside this block // Again, there's a chance that self was already deallocated, so // you could want to check if self == nil [self doSomeAwesomeStuff]; }]; }]; } 生成一个NuGet包。

http://dotnet.github.io/docs/core-concepts/libraries/libraries-with-cli.html

您不能指望旧版本的.NET Framework支持此类软件包,因为.NET Standard 1.5版本太高。