I created a NuGet package from my project. The output directory of the package is the solution directory. I would like to output it to a specific directory. I tried a target in the csproj file and in the nuspec file. None worked. How do I get the package generated in the specified folder?
In my .csproj:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
In my .nuspec:
<?xml version="1.0"?>
<package >
<metadata>
<id>MyPackage.dll</id>
<version>1.0.0</version>
<authors>me</authors>
<owners>me</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2016</copyright>
<files>
<file src="bin\MyPackage.dll" target="C:\LocalPackageRepository" />
</files>
</metadata>
</package>
Change NuGet package location folder Depending on what sort of project you are using this setting may or may not be successfully to change NuGet packager folder. If you are using a.NET Framework project that has a packages.config file then this setting will change the nuget package folder to C:projects.
Creates a NuGet package based on the specified .nuspec or project file. The dotnet pack command (see dotnet Commands) and msbuild -t:pack (see MSBuild targets) may be used as alternates. Use dotnet pack or msbuild -t:pack for PackageReference based projects. Under Mono, creating a package from a project file is not supported.
To change the nuget packager folder, you can you can set "NUGET_PACKAGES" environment variable. Just Set "NUGET_PACKAGES" = "c: eampackages". Or you can place a NuGet.Config file next to the solution with the following content: Dotnet restore does not honour nuget.config 'repositoryPath'.
Change the build output directory On the menu bar, choose Project > <Appname> Properties. If you have a Visual Basic project, select the Compile tab. In the configuration drop-down at the top, choose the configuration whose output file location you want to change (debug, release, or all).
In the 'old' way of NuGet (which you seem to use, check this for info on new vs old) this was possible by using the command in the .nuget\NuGet.targets file you mention. If you change the line with PackageOutputDir to below it will work.
<PackageOutputDir Condition="$(PackageOutputDir) == ''">C:\LocalPackageRepository</PackageOutputDir>
Even better would be to set a property on the PropertyGroup in the .csproj like this:
<PackageOutputDir>C:\LocalPackageRepository</PackageOutputDir>
In the new way of NuGet you would add this key to the NuGet.config file:
<add key="repositoryPath" value="C:\LocalPackageRepository" />
Not sure why the global config settings didn't work for me, but adding below solution solved my problem:
Variable name: MyNugetsOutput
Variable value: D:\myteam\teampackages
<Target Name="CopyPackage" AfterTargets="Pack">
<Copy SourceFiles="$(OutputPath)\$(PackageId).$(PackageVersion).nupkg"
DestinationFolder="$(MyNugetsOutput)\$(PackageId).$(PackageVersion).nupkg" />
</Target>
reference: Target build order
Currently I'm using below code, it is simpler but it copies all .nupkg files to the "Local" path
<Target Name="AfterPack" AfterTargets="Pack">
<Exec Command="dotnet nuget push $(PackageOutputPath)*.nupkg --source Local" />
</Target>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With