简体   繁体   English

nuget package 使用 VisualStudio 部署发布与 msbuild 发布

[英]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).我正在尝试将 a.netstandard2.0 class 库 nuget 部署到本地文件夹存储库(在 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.这可以通过 VisualStudio 对项目的发布上下文操作正常工作:幕后过程根据项目.csproj 构建项目并打包所需项目,然后根据 FolderProfile.pubxml 复制 nuget package。 I've expected this could be achieved with msbuild as well (to be used in scripts).我预计这也可以通过 msbuild 实现(用于脚本)。

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

This builds the project and copies content of bin/ Debug .netstandard2.0 to the local folder repository.这将构建项目并将 bin/ Debug.ne tstandard2.0 的内容复制到本地文件夹存储库。 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)不幸的是,这与要求的不同,PublishProfile 指定发布配置和项目.csproj 明确指出要打包的 just.dll(既不是.deps.json 也不是.pdb)

msbuild /t:Pack

Packs the nuget content according to the project .csproj but it leaves the package in bin/ Debug .根据项目.csproj 打包 nuget 内容,但将 package 留在 bin/ Debug中。

Switch to Release could be achieved via /p:Configuration=Release but that is still not enough to achieve the desired.切换到 Release 可以通过/p:Configuration=Release实现,但这仍然不足以达到预期的效果。

I've created simple a demonstration project, available at https://github.com/JanCervak/NugetPublishDifferenceRepro , local folder repository is set to %TEMP%我创建了一个简单的演示项目,可在https://github.com/JanCervak/NugetPublishDifferenceRepro获得,本地文件夹存储库设置为 %TEMP%

Used VS 2019 16.8.3使用 VS 2019 16.8.3

The publish button of VS IDE for class library projects is msbuild -t:pack rather than msbuild -t:publish . class 库项目的 VS IDE 的发布按钮是msbuild -t:pack而不是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.VS IDE上,当您单击 lib 项目的发布按钮时,它实际上会执行打包按钮以创建从pubxml文件读取的 nuget 包。 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.它是VS IDE的特殊功能,是由VS IDE中的集成任务、工具引起的。换句话说,它是由那个设计的。 For different vs projects , Publish Button does different functions.针对不同的 vs 项目Publish Button 的作用不同。

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).但是,当您使用msbuild -t:publish命令行中的 lib 项目时,它摆脱了 VS IDE 环境,它像 web 项目、windows 项目一样执行 function。(将最终的 88343718 文件放入自定义发布文件夹) .

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:因此,如果你想对 lib 项目使用与VS IDE相同的命令 function,你应该放弃pubxml文件并使用此命令:

  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. PackageOutputPath用于pack target,指定生成的路径 nuget package。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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