首页 > 解决方案 > 将静态文件添加到在 webproject 发布事件上发布到 wwwroot 的 Nuget 包

问题描述

我正在尝试构建一个带有静态文件(js、CSS 和图像)的 NuGet 包,可以在 Web 项目中作为包引用。我希望在触发发布时将这些文件发布到发布目录。

我的 .nuspec 配置是

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata minClientVersion="3.3.0">
    <id>Test.Assets.Develop</id>
    <version>1.0.0</version>
    <authors>Bev</authors>
    <owners>Bev</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Assets</description>
    <copyright>Copyright 2017</copyright>
    <contentFiles>
            <files include="contentFiles\any\any\assets\**" buildAction="Content" copyToOutput="true" flatten="false" />
    </contentFiles>
  </metadata>
  <files>
        <file src="build\assets\**" target="contentFiles\any\any\assets"/>
  </files>
</package>

我的静态文件被发布到<outputdir>/bin文件夹而不是<outputdir>.

标签: msbuildnugetnuspecpackagereference

解决方案


根据 MS 文档内容应复制到 nuget 包中的内容文件夹。

参考这里:https ://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package

内容文件可以放在内容文件夹 你可以使用这样的东西:

  <files>
       <file src="build\assets\**" target="content\" />
  </files>

推荐阅读