【发布时间】:2019-01-28 06:56:02
【问题描述】:
我正在尝试将 Nuget 包中的内容文件提取到引用我的包的项目中。
Packages.config 项目使用内容文件夹
Project.json/PackageReference/NETCore SDK 项目使用 contentFiles 文件夹
太好了,我创建了一个 .NET Core 2.1 控制台应用程序项目,并遵循了 NuGet ContentFiles Demystified 博客文章,该文章写于 2016 年 project.json,但现在应该仍然可以使用。
我在c:\dev\ContentFilesExample\contentFiles\any\any\images\dnf.png 创建了一个图像,然后创建了一个c:\dev\ContentFilesExample\ContentFilesExample.nuspec 文件并复制粘贴了内容:
<?xml version="1.0"?>
<package>
<metadata minClientVersion="3.3.0">
<id>ContentFilesExample</id>
<version>1.0.0</version>
<authors>nuget</authors> <!-- The NuGet team authored this package -->
<owners>nuget</owners> <!-- The NuGet team owns this package -->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A content v2 example package.</description>
<tags>contentv2 contentFiles</tags>
<!-- Build actions for items in the contentFiles folder -->
<contentFiles>
<!-- Include Assets as Content -->
<files include="**/images/*.*" buildAction="EmbeddedResource" />
</contentFiles>
</metadata>
</package>
然后我使用命令nuget pack ContentFilesExample.nuspec 生成了Nuget 包,并使用Nuget 包资源管理器打开它
太棒了,我的照片和预期的一样。
现在是最后的非工作步骤。我在我的 .NET Core 2.1 项目中安装了这个 Nuget 包,但图像丢失了。在我的项目的根目录中,obj 文件夹和 bin 文件夹中都没有图像的痕迹。
我尝试关闭并重新打开 Visual Studio,如某处某些 cmets 中所述,但这并没有解决问题。
我也尝试将我的 .NET Core 项目样式更改为 PackageReference 但同样,这并没有解决问题
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ContentFilesExample" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
那我做错了什么? .NET Core 真的支持 Nuget 包中的内容文件吗?
谢谢
【问题讨论】:
标签: c# .net-core nuget nuget-package