简体   繁体   中英

nuget package deploy with VisualStudio publish vs. msbuild publish

I'm trying to deploy a.netstandard2.0 class library nuget to a local folder repository (specified in FolderProfile.pubxml). This works fine via VisualStudio's publish context action on a project: the process behind the scenes builds the project and packs desired items according to project .csproj and then copies the nuget package according to FolderProfile.pubxml. I've expected this could be achieved with msbuild as well (to be used in scripts).

msbuild /t:Publish /p:PublishProfile=FolderProfile.pubxml 

This builds the project and copies content of bin/ Debug .netstandard2.0 to the local folder repository. Unfortunately this differs from what was requested, the PublishProfile specifies Release configuration and project .csproj explicitly states just.dll to be packed (neither.deps.json nor.pdb)

msbuild /t:Pack

Packs the nuget content according to the project .csproj but it leaves the package in bin/ Debug .

Switch to Release could be achieved via /p:Configuration=Release but that is still not enough to achieve the desired.

I've created simple a demonstration project, available at https://github.com/JanCervak/NugetPublishDifferenceRepro , local folder repository is set to %TEMP%

Used VS 2019 16.8.3

The publish button of VS IDE for class library projects is msbuild -t:pack rather than msbuild -t:publish .

On VS IDE , when you click on the Publish button for lib projects, it actually does Pack button to create the nuget packages which reads from the pubxml file. It is the special feature of VS IDE and caused by the integrated tasks, tools from VS IDE. In other words, it is designed by that. For different vs projects , Publish Button does different functions.

However , when you use msbuild -t:publish for lib projects from command line, which gets rid of the VS IDE environment, it does the function like the web projects, windows projects.(put the final output files into the custom publish folder).

So if you want to use commands which does the same function as VS IDE for lib projects, you should abandon the pubxml file and use this command:

  msbuild NugetPublishDifferenceRepro.csproj -t:pack -p:Configuration=Release;Platform=AnyCPU;PackageOutputPath=%Temp%

PackageOutputPath is for pack target and specify the path of the generated nuget package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM