问题
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.
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 asPlugins.props
so that it will work.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>
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>
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