9

MSBuild 常用参数

 3 years ago
source link: https://lindexi.gitee.io/post/MSBuild-%E5%B8%B8%E7%94%A8%E5%8F%82%E6%95%B0.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

本文告诉大家在 MSBuild 里面常用的参数

一般的 msbuild 在编译的时候都会添加很多参数,用法如下

进入对应编译的 sln 或 csproj 文件所在的文件夹,执行下面命名

msbuild 

如果在文件夹里面存在多个不同的 sln 文件等,在 msbuild 后面添加对应的文件

msbuild xx.sln

此外添加的参数写在 msbuild 后面

还原加构建

原先的 msbuild 之前是需要调用 nuget restore 但当前可以不加上 nuget 还原,由 msbuild 自己还原

msbuild -restore

以上代码等价于

msbuild -t:restore,build

详细请看 NuGet pack and restore as MSBuild targets

有多个项目一起编译,通过并行编译可以加快速度

/m 参数开启并行编译

msbuild /m

通过后面带上数字表示多少 CPU 同时编译,下面代码表示 6 个 CPU 同时编译

msbuild /m:6

发布版编译

通过发布版编译就是设置 configuration 属性为 release 通过下面代码

msbuild /p:Configuration=Release

在msbuild通过 /p 设置对应的属性的值

在 msbuild 的参数是不区分 /- 也就是 /p-p 是相同

msbuild /p:Configuration=Release -restore

通过 -t:rebuild 重新编译

msbuild -t:rebuild 

通过 -fileLogger-fl 可以指定输出到文件,通过 -filelogparameters 或短参数 flp 可以指定输出的日志文件

msbuild -fl -flp:logfile=xx.log;verbosity=n

这里的 verbosity 表示输出等级

运行上面代码建议编译当前文件夹里面的项目,然后将编译日志输出到 xx.log 文件夹

执行包还原

通过 -t:restore 可以还原包

msbuild -t:restore

建议的还原方法是下面代码

 NuGet restore
 dotnet restore
 msbuild -t:restore

通过 -t:clean 清理项目

msbuild -t:clean

通过 /t:pack 打包

msbuild -t:pack

UWP 打包

msbuild /t:restore /t:Publish /p:Configuration=Release /p:AppxPackageDir="D:\lindexi\AppxPackages\\" /p:AppxBundle=Always /p:UapAppxPackageBuildMode=StoreUpload /p:AppxBundlePlatforms="x86|x64|arm"

本文会经常更新,请阅读原文: https://blog.lindexi.com/post/MSBuild-%E5%B8%B8%E7%94%A8%E5%8F%82%E6%95%B0.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。

如果你想持续阅读我的最新博客,请点击 RSS 订阅,推荐使用RSS Stalker订阅博客,或者前往 CSDN 关注我的主页

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接: https://blog.lindexi.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系

无盈利,不卖课,做纯粹的技术博客

以下是广告时间

推荐关注 Edi.Wang 的公众号
lindexi%2F201985113622445

欢迎进入 Eleven 老师组建的 .NET 社区
lindexi%2F20209121930471745.jpg

以上广告全是友情推广,无盈利


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK