安装Nuget软件包时,将文件从Nuget软件包复制到目标项目

发布于 2025-01-20 20:12:44 字数 9141 浏览 4 评论 0原文

我正在研究模块开发的打包部分,并且我能够成功创建包并将其安装在目标站点上。

但我在安装时将文件复制到目标项目中的模块文件夹时遇到问题。它为文件夹创建一些引用,而不是真正的文件夹。目标项目的模块文件夹中没有创建任何物理文件。但我们注意到它是在我的计算机上的全局 NuGet 文件夹中创建的(C:\Users.nuget\packages)。 检查以下屏幕截图

参考解决方案视图

在全局 NuGet 文件夹中创建的物理文件

我正在使用 Package.nuspec 文件和 .targets 文件,如下所示:

Package.nuspec

<?xml version="1.0"?>
<package >
  <metadata xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
    <id>QBankModule6</id>
    <version>6.0.74</version>
    <title>QBank Module 6</title>
    <authors>QBNK AB</authors>
    <owners />
    <iconUrl>http://nuget.episerver.com/Framework/Styles/images/icons/default_package_icon.png</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>QBank Module is a module for media support. The module includes a QBank tool for EPiServer.Cms.TinyMce 2.1.1.0 or higher versions and media references.  IMPORTANT: After first install, go to Admin mode to initiate QBank.</description>
    <tags>EPiServerModulePackage ThirdPartyAddOn Media Images DAM Mediabank Streaming QBank</tags>
    <dependencies>
      <group targetFramework="net5.0">
        <dependency id="EPiServer.CMS.Core" version="[12.0.3, 13)" />
        <dependency id="RestSharp" version="106.11.7" />
        <dependency id="log4net" version="[2.0.0, 2.9999)" />
        <dependency id="HtmlAgilityPack" version="[1.8.4.0, 1.8.4.9)" />
      </group>
    </dependencies>
    <contentFiles>
      <files include="any/any/modules/_protected/QBankModule/ClientResources/Scripts/Editors/QBankMediaPicker.js" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/ClientResources/Scripts/qbank-connector.js" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/ClientResources/Scripts/QBankResponsiveLight-1.0.js" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/ClientResources/Scripts/jquery.js" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/ClientResources/Styles/qbankplugin.css" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/TinyPlugin/editor_plugin.js" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/module.config" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/lang/QbankModule_lang.xml" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/QBankModule.zip" buildAction="None" copyToOutput="true"/>
      
      <files include="any/any/web.config.install.xdt" buildAction="None" copyToOutput="true"/>
      <files include="any/any/web.config.uninstall.xdt" buildAction="None" copyToOutput="true"/>
      
      <files include="any/any/QbankApi.dll" buildAction="Compile" copyToOutput="true"/>
      <files include="any/any/Qbank.Connector.Core.dll" buildAction="Compile" copyToOutput="true"/>
      <files include="any/any/Qbank.Connector.EpiCore.dll" buildAction="Compile" copyToOutput="true"/>
      <files include="any/any/Qbank.Connector.EpiCore11.dll" buildAction="Compile" copyToOutput="true"/>
      <files include="any/any/Qbank.Connector.EpiServerModule5.dll" buildAction="Compile" copyToOutput="true"/>
      
    </contentFiles>
                        
    
  </metadata>
  <files>
    <file src="Qbank.Connector.EpiServerModule5/build/QBankModule6.targets" target="lib/net5.0" />
    <file src="Qbank.Connector.EpiServerModule5/bin/net5.0/QbankApi.dll" target="lib/net5.0" />
    <file src="Qbank.Connector.EpiServerModule5/bin/net5.0/Qbank.Connector.Core.dll" target="lib/net5.0" />
    <file src="Qbank.Connector.EpiServerModule5/bin/net5.0/Qbank.Connector.EpiCore.dll" target="lib/net5.0" />
    <file src="Qbank.Connector.EpiServerModule5/bin/net5.0/Qbank.Connector.EpiCore11.dll" target="lib/net5.0" />
    <file src="Qbank.Connector.EpiServerModule5/bin/net5.0/Qbank.Connector.EpiServerModule5.dll" target="lib/net5.0" />
    <!--<file src="Qbank.Connector.EpiServerModule5/ClientResources/Images/qbank-loader.gif" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Images/qbank-loader.gif" />-->
    <!--<file src="Qbank.Connector.EpiServerModule5/ClientResources/Images/qbankadd.png" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Images/qbankadd.png" />-->
    <file src="Qbank.Connector.EpiServerModule5/ClientResources/Scripts/Editors/QBankMediaPicker.js" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Scripts/Editors/QBankMediaPicker.js" />
    <file src="Qbank.Connector.EpiServerModule5/ClientResources/Scripts/qbank-connector.js" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Scripts/qbank-connector.js" />
    <file src="Qbank.Connector.EpiServerModule5/ClientResources/Scripts/QBankResponsiveLight-1.0.js" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Scripts/QBankResponsiveLight-1.0.js" />
    <file src="Qbank.Connector.EpiServerModule5/ClientResources/Scripts/jquery.js" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Scripts/jquery.js" />
    <file src="Qbank.Connector.EpiServerModule5/ClientResources/Styles/qbankplugin.css" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Styles/qbankplugin.css" />
    <file src="Qbank.Connector.EpiServerModule5/TinyPlugin/editor_plugin.js" target="contentFiles/any/any/modules/_protected/QBankModule/TinyPlugin/editor_plugin.js" />
    <!--<file src="Qbank.Connector.EpiServerModule5/TinyPlugin/Img/qbank.png" target="contentFiles/any/any/modules/_protected/QBankModule/TinyPlugin/Img/qbank.png" />-->
    <file src="Qbank.Connector.EpiServerModule5/module.config" target="contentFiles/any/any/modules/_protected/QBankModule/module.config" />
    <file src="Qbank.Connector.EpiServerModule5/Lang/QbankModule_lang.xml" target="contentFiles/any/any/modules/_protected/QBankModule/lang/QbankModule_lang.xml" />
    <file src="Qbank.Connector.EpiServerModule5/web.config.install.xdt" target="contentFiles/any/any"/>
    <file src="Qbank.Connector.EpiServerModule5/web.config.uninstall.xdt" target="contentFiles/any/any"/>
    <!--CDN Solution-->
    <!--<file src="Qbank.Connector.EpiServerModule5/ClientResources/Images/qbankaudio.png" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Images/qbankaudio.png" />-->
    <!--<file src="Qbank.Connector.EpiServerModule5/ClientResources/Images/qbankdocument.png" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Images/qbankdocument.png" />-->
    <!--<file src="Qbank.Connector.EpiServerModule5/ClientResources/Images/qbankvideo.png" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Images/qbankvideo.png" />-->
    <!--<file src="Qbank.Connector.EpiServerModule5/build/QBankModule6.props" target="build" />-->
    <file src="Qbank.Connector.EpiServerModule5/build/QBankModule6.targets" target="build" />
    <file src="Qbank.Connector.EpiServerModule5/QbankModule.zip" target="contentFiles/any/any/modules/_protected/QBankModule/QBankModule.zip" />

  </files>
</package>

QBankModule6.targets

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">

  <ItemGroup>
    <SourceScripts Include="$(MSBuildThisFileDirectory)..\..\contentFiles\any\any\modules\_protected\**\*.*"/>
  </ItemGroup>

  <Target Name="CopyZipFiles" BeforeTargets="Build">
    <Copy
            SourceFiles="@(SourceScripts)"
            DestinationFolder="$(MSBuildProjectDirectory)\modules\_protected\%(RecursiveDir)"
        />
  </Target>
</Project>

另外,我发现这个 发布帖子中提到的已实施的解决方案。但最终得到了相同的结果。

基本上,我需要了解在安装nuget包时如何将一些文件从NuGet包复制到目标项目。还有 nuspec 文件中 标记和 标记之间的区别。

有这方面经验的人的任何意见都会很棒!

I'm working on the packaging part of module development and I was able to successfully create the package and install it on the destination site.

But I have an issue with copying files to the module folder in the destination project when installing. It creates some references for folders, not real folders. There are no physical files created in the modules folder in the destination project. But we noticed that it was created in the global NuGet folder on my computer (C:\Users<User>.nuget\packages).
Check the following Screenshots

Solution View with reference

Physical files created in global NuGet folder

I'm using Package.nuspec file and .targets file as follows:

Package.nuspec

<?xml version="1.0"?>
<package >
  <metadata xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
    <id>QBankModule6</id>
    <version>6.0.74</version>
    <title>QBank Module 6</title>
    <authors>QBNK AB</authors>
    <owners />
    <iconUrl>http://nuget.episerver.com/Framework/Styles/images/icons/default_package_icon.png</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>QBank Module is a module for media support. The module includes a QBank tool for EPiServer.Cms.TinyMce 2.1.1.0 or higher versions and media references.  IMPORTANT: After first install, go to Admin mode to initiate QBank.</description>
    <tags>EPiServerModulePackage ThirdPartyAddOn Media Images DAM Mediabank Streaming QBank</tags>
    <dependencies>
      <group targetFramework="net5.0">
        <dependency id="EPiServer.CMS.Core" version="[12.0.3, 13)" />
        <dependency id="RestSharp" version="106.11.7" />
        <dependency id="log4net" version="[2.0.0, 2.9999)" />
        <dependency id="HtmlAgilityPack" version="[1.8.4.0, 1.8.4.9)" />
      </group>
    </dependencies>
    <contentFiles>
      <files include="any/any/modules/_protected/QBankModule/ClientResources/Scripts/Editors/QBankMediaPicker.js" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/ClientResources/Scripts/qbank-connector.js" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/ClientResources/Scripts/QBankResponsiveLight-1.0.js" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/ClientResources/Scripts/jquery.js" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/ClientResources/Styles/qbankplugin.css" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/TinyPlugin/editor_plugin.js" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/module.config" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/lang/QbankModule_lang.xml" buildAction="None" copyToOutput="true"/>
      <files include="any/any/modules/_protected/QBankModule/QBankModule.zip" buildAction="None" copyToOutput="true"/>
      
      <files include="any/any/web.config.install.xdt" buildAction="None" copyToOutput="true"/>
      <files include="any/any/web.config.uninstall.xdt" buildAction="None" copyToOutput="true"/>
      
      <files include="any/any/QbankApi.dll" buildAction="Compile" copyToOutput="true"/>
      <files include="any/any/Qbank.Connector.Core.dll" buildAction="Compile" copyToOutput="true"/>
      <files include="any/any/Qbank.Connector.EpiCore.dll" buildAction="Compile" copyToOutput="true"/>
      <files include="any/any/Qbank.Connector.EpiCore11.dll" buildAction="Compile" copyToOutput="true"/>
      <files include="any/any/Qbank.Connector.EpiServerModule5.dll" buildAction="Compile" copyToOutput="true"/>
      
    </contentFiles>
                        
    
  </metadata>
  <files>
    <file src="Qbank.Connector.EpiServerModule5/build/QBankModule6.targets" target="lib/net5.0" />
    <file src="Qbank.Connector.EpiServerModule5/bin/net5.0/QbankApi.dll" target="lib/net5.0" />
    <file src="Qbank.Connector.EpiServerModule5/bin/net5.0/Qbank.Connector.Core.dll" target="lib/net5.0" />
    <file src="Qbank.Connector.EpiServerModule5/bin/net5.0/Qbank.Connector.EpiCore.dll" target="lib/net5.0" />
    <file src="Qbank.Connector.EpiServerModule5/bin/net5.0/Qbank.Connector.EpiCore11.dll" target="lib/net5.0" />
    <file src="Qbank.Connector.EpiServerModule5/bin/net5.0/Qbank.Connector.EpiServerModule5.dll" target="lib/net5.0" />
    <!--<file src="Qbank.Connector.EpiServerModule5/ClientResources/Images/qbank-loader.gif" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Images/qbank-loader.gif" />-->
    <!--<file src="Qbank.Connector.EpiServerModule5/ClientResources/Images/qbankadd.png" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Images/qbankadd.png" />-->
    <file src="Qbank.Connector.EpiServerModule5/ClientResources/Scripts/Editors/QBankMediaPicker.js" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Scripts/Editors/QBankMediaPicker.js" />
    <file src="Qbank.Connector.EpiServerModule5/ClientResources/Scripts/qbank-connector.js" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Scripts/qbank-connector.js" />
    <file src="Qbank.Connector.EpiServerModule5/ClientResources/Scripts/QBankResponsiveLight-1.0.js" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Scripts/QBankResponsiveLight-1.0.js" />
    <file src="Qbank.Connector.EpiServerModule5/ClientResources/Scripts/jquery.js" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Scripts/jquery.js" />
    <file src="Qbank.Connector.EpiServerModule5/ClientResources/Styles/qbankplugin.css" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Styles/qbankplugin.css" />
    <file src="Qbank.Connector.EpiServerModule5/TinyPlugin/editor_plugin.js" target="contentFiles/any/any/modules/_protected/QBankModule/TinyPlugin/editor_plugin.js" />
    <!--<file src="Qbank.Connector.EpiServerModule5/TinyPlugin/Img/qbank.png" target="contentFiles/any/any/modules/_protected/QBankModule/TinyPlugin/Img/qbank.png" />-->
    <file src="Qbank.Connector.EpiServerModule5/module.config" target="contentFiles/any/any/modules/_protected/QBankModule/module.config" />
    <file src="Qbank.Connector.EpiServerModule5/Lang/QbankModule_lang.xml" target="contentFiles/any/any/modules/_protected/QBankModule/lang/QbankModule_lang.xml" />
    <file src="Qbank.Connector.EpiServerModule5/web.config.install.xdt" target="contentFiles/any/any"/>
    <file src="Qbank.Connector.EpiServerModule5/web.config.uninstall.xdt" target="contentFiles/any/any"/>
    <!--CDN Solution-->
    <!--<file src="Qbank.Connector.EpiServerModule5/ClientResources/Images/qbankaudio.png" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Images/qbankaudio.png" />-->
    <!--<file src="Qbank.Connector.EpiServerModule5/ClientResources/Images/qbankdocument.png" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Images/qbankdocument.png" />-->
    <!--<file src="Qbank.Connector.EpiServerModule5/ClientResources/Images/qbankvideo.png" target="contentFiles/any/any/modules/_protected/QBankModule/ClientResources/Images/qbankvideo.png" />-->
    <!--<file src="Qbank.Connector.EpiServerModule5/build/QBankModule6.props" target="build" />-->
    <file src="Qbank.Connector.EpiServerModule5/build/QBankModule6.targets" target="build" />
    <file src="Qbank.Connector.EpiServerModule5/QbankModule.zip" target="contentFiles/any/any/modules/_protected/QBankModule/QBankModule.zip" />

  </files>
</package>

QBankModule6.targets

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">

  <ItemGroup>
    <SourceScripts Include="$(MSBuildThisFileDirectory)..\..\contentFiles\any\any\modules\_protected\**\*.*"/>
  </ItemGroup>

  <Target Name="CopyZipFiles" BeforeTargets="Build">
    <Copy
            SourceFiles="@(SourceScripts)"
            DestinationFolder="$(MSBuildProjectDirectory)\modules\_protected\%(RecursiveDir)"
        />
  </Target>
</Project>

Also, I found this post an implemented solutions mentioned in the post. But ended up with the same result.

Basically, I need to understand how to copy some files from the NuGet package to the destination project when installing the nuget package. And also the difference between <files> tag and <contentFiles> tag in nuspec file.

Any input from someone who has experience on this would be great!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文