Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

nuget add does not work in msbuild exec command

$
0
0

I am trying to automate process Build -> Pack -> Add for nuget package in VS2022. I have created SDK type project and using default settings to create nuget package. After executing Pack Command in Release mode, I have the following output in /bin/Release/ folder:

net8.0/    contains library filesmy-package.nupkg 

So far so good. Now I would like to execute nuget add command automatically after the Pack command completed, and publish the nuget package to my local repository. When I start power shell in the folder where csproj file is, and execute the following command:

nuget add bin/Release/my-package.0.0.1.nupkg -Source 'c:\Users\MyUser\OneDrive\nuget\packages\'

the command completes successfully, and I can see and use the package from other solutions.

However, if I try to automate this, it does not work. In csproj file:

<Target Name="AddPackage" AfterTargets="Pack" Condition=" '$(Configuration)' == 'Release'"><Message Text="Adding nuget file to local repository..." Importance="high" /><Exec Command="nuget add bin/Release/$(PackageId).$(PackageVersion).nupkg -Source 'c:\Users\MyUser\OneDrive\nuget\packages\'" /></Target>

Output window shows error:

1>Adding nuget file to local repository...1>The given path's format is not supported.error MSB3073: The command "nuget add bin/Release/my-package.0.0.1.nupkg -Source 'c:\Users\MyUser\OneDrive\nuget\packages\'" exited with code 1.

I also tried without relative path:

Command="nuget add $(PackageId).$(PackageVersion).nupkg -Source ....Command="nuget add my-package.0.0.1.nupkg -Source ....

and copied manually the nupkg file in csproj folder, and same error.

Anyone knows why is it working from command line and not from VS, and how can I automate this task from VS Build/Pack process?


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>