【发布时间】:2019-09-26 15:45:34
【问题描述】:
我正在尝试创建一个 .NET 标准 nuget 内容文件包(没有托管程序集),以供 .NET Framework 程序集使用。我的目标是将这个文件夹中的文件复制到消费程序集的 bin 文件夹中。
这个问题与Add native files from NuGet package to project output directory 类似(并使用此nuget 包http://www.nuget.org/packages/Baseclass.Contrib.Nuget.Output/),但我要求我的nuget 包为.NET Standard
我已在 contentfiles\any\any\myfiles 下的程序集中添加文件,并将以下内容添加到 nuspec 文件的元数据部分:
<contentFiles>
<files include="any/any/myfiles/*" buildAction="None" copyToOutput="true" />
</contentFiles>
当我尝试将其添加到 .NET 框架程序集时,我收到错误
无法安装软件包“myPackage 1.0.0”。您正在尝试将此包安装到以“.NETFramework,Version=v4.6.2”为目标的项目中,但该包不包含任何与该框架兼容的程序集引用或内容文件。如需更多信息,请联系包作者。
我还尝试将文件添加到项目的根目录,并在 nuspec 文件的元数据元素下方添加以下内容:
<files>
<file src="myfiles\**\*" target="myfiles" />
</files>
完整的 nuspec 文件:
<?xml version="1.0"?>
<package>
<metadata>
<id>myPackage</id>
<version>1.0.0</version>
<title>myPackage</title>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>my files/description>
<releaseNotes></releaseNotes>
<tags></tags>
<contentFiles>
<files include="any/any/myfiles/*" buildAction="None" copyToOutput="true" />
</contentFiles>
</metadata>
<files>
<file src="myfiles\**\*" target="myfiles" />
</files>
</package>
另外,在 csproj 中,我还将 TargetFramework 元素更改为:
<TargetFrameworks>netstandard1.3;netstandard2.0;net40;net45;net46</TargetFrameworks>
解决方案:
最后,这是解决方案:“myFiles”是位于项目根目录中的文件夹,包含许多不同的文件和子目录。
nuspec 文件:
<?xml version="1.0"?>
<package >
<metadata>
<id>myPackage</id>
<version>1.0.0</version>
<title>My Package</title>
<tags></tags>
<dependencies>
<group targetFramework=".NETStandard2.0" />
<group targetFramework=".NETFramework4.6.2" />
</dependencies>
<contentFiles>
<!-- this sets "CopyIfNewer" on all files in the project that references this package -->
<files include="**/*" buildAction="None" copyToOutput="true"/>
</contentFiles>
</metadata>
<files>
<file src="myFiles\**\*" target="contentFiles\any\any\myFiles"/>
</files>
</package>
引用 nuget 包的项目似乎有一个名为“myfiles”的文件夹(所有文件上都有一个链接图标),该文件夹将在构建时复制到 bin 文件夹。
【问题讨论】:
-
我最初认为构建操作应该类似于“嵌入式资源”或“内容”,而不是“无”。我将关闭 Visual Studio 中可用的选项。也许最好将其作为“Resource1.resx”文件,并将文件链接到该文件?
-
没有。 @DanRayson 它不是那样工作的。这些类型的项目有效地通过目标框架构建多个 dll。相反,这里提出的问题是关于项目未定位
net462 -
另外,在 csproj 中,我还将 TargetFramework 更改为 TargetFrameworks "netstandard1.3;netstandard2.0;net40;net45;net46"
-
必须是
net462
标签: c# .net nuget .net-standard