Restore nuget package in different folder

穿精又带淫゛_ 提交于 2021-01-29 06:42:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/65285966/restore-nuget-package-in-different-folder

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