在不同的文件夹中恢复nuget包 [英] Restore nuget package in different folder

查看:35
本文介绍了在不同的文件夹中恢复nuget包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些项目(插件)在多个项目中使用,这些项目的输出将复制到目标项目中的特定文件夹(插件文件夹).我们使用 Visual Studio 2019 Pack 选项打包项目,然后将 npkg 文件推送到本地 NuGet 服务器以供进一步使用.

问题是当我们想要获取这些包时,包管理器应该将lib文件放在Plugins文件夹中,但不幸的是,包管理器将这些文件解压到根文件夹(bin)中.

我的问题是:如何配置 nuspec 文件以强制包管理器解压缩到正确的文件夹,我可以使用 Visual Studio 执行此操作,还是必须手动创建 nuspec 文件.

解决方案

您应该使用

  • 将这些添加到 Plugins.props 文件中:

    <项目><目标名称=复制文件"BeforeTargets=构建"><项目组><File Include="$(MSBuildThisFileDirectory)..\Plugins\*.*></File></项目组><!--它会将插件输出文件复制到目标项目的Plugins文件夹中--><Copy SourceFiles="@(File)";DestinationFolder=$(ProjectDir)Plugins"></Copy></目标></项目>

  • 将这些添加到 Plugins.csproj 文件中:

    <None Include="bin\Debug\netstandard2.0\Plugins.dll";包=真"PackagePath=插件"></None>//从插件项目中添加您希望它们被打包的任何输出文件<None Include="build\Plugins.props";包=真"PackagePath=build"></项目组>

  • 使用 Pack 按钮创建 nuget 包的新发布版本.

  • 另外,当你安装这个新版本的 nuget 包时,请清理你的 nuget 缓存或删除 C:\Users\xxx(current user)\.nuget\packages 下的所有文件.

    完成安装过程后,请点击Build按钮,文件将在Plugins文件夹下生成.

    还有 关于此的类似问题.

    We have some projects (Plugins) which use in several projects, the output of these projects will copy to the specific folder in the target projects (Plugins folder). We pack project with Visual studio 2019 Pack option and after that, we push npkg files to our local NuGet server for further use.

    The problem is when we want to get these packages, Package Manager should put lib files in the Plugins folder, but unfortunately, the package manager extracts these in the root folder (bin).

    My question is: How can I config nuspec file to force package manager to extract to the right folder, and can I do it with visual studio or I have to create nuspec file manually.

    解决方案

    You should use a <packages_id>.props file to realize it.

    1. create a file called <packages_id>.props under the build folder of your lib project.

      You should note that if your nupkg file is called Plugins.1.0.0.nupkg, you should name this file as Plugins.props so that it will work.

    2. add these on Plugins.props file:

      <Project>
      
          <Target Name="CopyFiles" BeforeTargets="Build">
              <ItemGroup>
                  <File Include="$(MSBuildThisFileDirectory)..\Plugins\*.*"></File>
              </ItemGroup>
      
               <!--It will copy the plugins output files into the Plugins folder of the goal project-->
              <Copy SourceFiles="@(File)" DestinationFolder="$(ProjectDir)Plugins"></Copy>
      
          </Target>
      
      </Project>
      

    3. add these on Plugins.csproj file:

      <ItemGroup>
              <None Include="bin\Debug\netstandard2.0\Plugins.dll" Pack="true" PackagePath="Plugins"></None>
      
              //add any output files from Plugins project which you want them to be packed 
      
              <None Include="build\Plugins.props" Pack="true" PackagePath="build"></None>
          </ItemGroup>
      

    4. use Pack Button to create the new release version of your nuget pakckage.

    Also, when you install this new version of nuget package, please clean your nuget caches or delete all files under C:\Users\xxx(current user)\.nuget\packages.

    When you finish the installing process, please click Build button and the files will generated under Plugins folder.

    There is also a similar issue about this.

    这篇关于在不同的文件夹中恢复nuget包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆