内容在 ASP.net 5 中的 Nuget 包

Nuget Packages with content in ASP.net 5

我有几个包含内容文件的包(一个例子是用于从用户代理获取设备数据的 wurfl 包,它在标记为内容的 nuget 包中包含它的数据库文件)。

在 asp.net 5 设置中添加这些包时,内容不会添加到任何地方。

从哪里或如何获取添加到我的解决方案中的这些 nuget 包的内容?

http://blog.nuget.org/20150729/Introducing-nuget-uwp.html

Deprecated Features

Starting with NuGet 3.1 when using project.json, we are deprecating support for executing the install.ps1/uninstall.ps1 scripts and delivering elements in the /content folder of packages. Installing packages that have these elements will not execute the install.ps1 file and will not copy content to your project.

阅读 link 了解更多关于为什么...

这是一个老问题,但我的解决方案似乎仍然适用于 Net 5。它是:

像这样在您的包中包含一个 YourPacakgeName.targets 文件:

<file src="YourPacakgeName.targets" target="build" />

.targets 文件的内容应该是:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <MySourceFiles Include="$(MSBuildThisFileDirectory)..\Content\**\*.*"/>
  </ItemGroup>
  <Target Name="CopyFiles" BeforeTargets="Build" AfterTargets="Clean">
    <Copy
      SourceFiles="@(MySourceFiles)"
      DestinationFolder="$(MSBuildProjectDirectory)\%(RecursiveDir)"
      SkipUnchangedFiles="true"
    />
  </Target>
</Project>

实际上,这会在构建之前和清理操作之后复制内容文件。