Packing static content in Nuget for PackageReferece projects

房东的猫 提交于 2019-12-05 12:07:37

Installation is ignoring my build action. Why is always trying to compile my content files? Is there a better way to add static content to the consumer project?

To answer your previous question Packing files on nuget, I have created a sample nuget package and set the build action to content for the content files, after install that nuget package, the build action would be set content:

Then I checked your .nuspec file, found it should be correct. So the issue is not related to your .nuspec file.

Besides, in the above image, you will notice that the path of the content file is nuget local cache:

C:\Users\<UserName>\.nuget\packages\

NuGet will first extract the nuget package from the local cache when install the nuget package to avoid downloading packages that are already on the computer. In other wards, although we have updated the nuget package in the local, nuget will detect the local cache first, if it found the same package in the cache, nuget will install it from cache rather than local feed.

To resolve this issue, please try to remove your nuget package in the local cache before installing the updated nuget package. Generally, when we package the same package again, wed better change the package version in the.nuspec` file so nuget local cache will not catch them.

Update for comment:

I've tried increasing the version number and deleting the nuget cache and the problem persists. My build action is always set to "C# Compiler". I just tried changing the name of the js file and the project imports the new name so I do not think it's a cache problem

After test your nuget package, I found the reason why you get that issue, we should keep the path the src and target paths are the same in the .nuspec file. Since you want set content file to the wwwroot folder, you should set the file in the wwwroot folder, then pack the .nuspec:

<contentFiles>
  <files include="any/any/wwwroot/css/bd.css" buildAction="Content" copyToOutput="false" flatten="true" />
  <files include="any/any/wwwroot/js/bd.js" buildAction="Content" copyToOutput="false" flatten="true" />
</contentFiles>

Following in my .nuspec scripts(Not need content node):

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>BancaDigitalViewProvider</id>
    <version>1.0.37</version>
    <authors>Ibercaja</authors>
    <owners>Ibercaja</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Login View Provider</description>
    <copyright>Copyright 2018</copyright>
    <tags>Banca Digital View Provider</tags>
    <dependencies />
    <contentFiles>
      <files include="any/any/wwwroot/css/bd.css" buildAction="Content" copyToOutput="false" flatten="true" />
      <files include="any/any/wwwroot/js/bd.js" buildAction="Content" copyToOutput="false" flatten="true" />
    </contentFiles>
  </metadata>

  <files>
    <file src="contentFiles/any/any/wwwroot/css/bd.css" target="contentFiles/any/any/wwwroot/css/bd.css" />
    <file src="contentFiles/any/any/wwwroot/js/bd.js" target="contentFiles/any/any/wwwroot/js/bd.js" />
    <file src="bin\debug\BancaDigitalViewProvider.dll" target="lib\net47\BancaDigitalViewProvider.dll" />
  </files>
</package>

This is nuget package:

https://1drv.ms/u/s!Ai1sp_yvodHfhTk5xutPpaBZLC-A

You can download it and test.

Then install it to the ASP.NET core MVC project:

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!