Msbuild命令行参数在项目级别不解决方案级别更改AssemblyName [英] Msbuild command line argument at project-level not solution-level for changing AssemblyName
问题描述
在构建多项目解决方案时,是否有任何方法为msbuild指定仅适用于一个项目(即项目级别不是解决方案级别)的命令行参数?
我问的原因是因为我想启用单击部署的并行安装。让我举个例子:
1)这样工作
MSBuildC :\Dev\MyProj\MyProj.Shell\MyProj.Shell.csproj
/ p:SkipInvalidConfigurations = true / target:publish
/ p:OutputPath =C:\Dev\\ \\ Temp \/p:ApplicationVersion=1.2.3.4
/ p:ProductName =My Proj/ p:Configuration =Release/ p:Platform =Mixed
Platforms/ verbosity:诊断
2)这不会
MSBuildC:\Dev\MyProj\MyProj.Shell\MyProj.Shell.csproj
/ p:SkipInvalidConfigurations = true / target:publish
/ p:OutputPath =C :\Dev\Temp\/p:ApplicationVersion=1.2.3.4
/ p:ProductName =My Proj Test/ p:Configuration =Release
/ p:Platform =混合平台/ verbosity:diagnostic
/p:AssemblyName=\"MyProj.Test
迭代几个点:
- 1& 2是
/ p:AssemblyName =MyProj.Text
- 我使用
/ target:
- 这是一个多项目解决方案,即使我只是针对一个csproj文件,它也会如此构建。我知道示例2 失败的原因是因为它使用程序集名称重命名每个项目的AssemblyName传入,即 MyProj.Test 。这有一些意义,因为通过命令行传递的参数是全局的,但是我又指向只是csproj文件。
反正这就是发生了什么。所以有什么办法传递一个msbuild命令行参数只更改MyProj.Shell.csproj文件中的一个AssemblyName属性?
解决方案您可以编辑有问题的项目(其 .csproj 文件),以便从指定的特殊属性获取程序集名称,例如:
< AssemblyName Condition ='$(ThisProjectNameOverrideAssemblyName)'==''> UsualAssemblyName< / AssemblyName>
< AssemblyName Condition ='$(ThisProjectNameOverrideAssemblyName)'!=''> $(ThisProjectNameOverrideAssemblyName)< / AssemblyName>
所以当你构建你的项目时,你传递
ThisProjectNameOverrideAssemblyName
仅覆盖此项目的
AssemblyName
:msbuild / p:ThisProjectNameOverrideAssemblyName = NewAssemblyName
Is there any way to specify a command line argument for msbuild that will apply only to one project (i.e. project-level not solution-level), when building a multi-project solution?
The reason I ask is because I want to enable side-by-side installs of a click-once deployment. Let me give an example:
1) This works
MSBuild "C:\Dev\MyProj\MyProj.Shell\MyProj.Shell.csproj" /p:SkipInvalidConfigurations=true /target:publish /p:OutputPath="C:\Dev\Temp\" /p:ApplicationVersion=1.2.3.4 /p:ProductName="My Proj" /p:Configuration="Release" /p:Platform="Mixed Platforms" /verbosity:diagnostic
2) This doesn't
MSBuild "C:\Dev\MyProj\MyProj.Shell\MyProj.Shell.csproj" /p:SkipInvalidConfigurations=true /target:publish /p:OutputPath="C:\Dev\Temp\" /p:ApplicationVersion=1.2.3.4 /p:ProductName="My Proj Test" /p:Configuration="Release" /p:Platform="Mixed Platforms" /verbosity:diagnostic /p:AssemblyName="MyProj.Test"
Just to clarify and re-iterate a couple of points:
- The only difference between 1 & 2 is the
/p:AssemblyName="MyProj.Text"
- I'm using
/target:publish
so this is a click-once build - This is a multi-project solution and it will build as such even though I'm just targeting a csproj file.
I know the reason why Example 2 fails is because it renames every project's AssemblyName with the assembly name passed in, i.e. MyProj.Test. This makes some sense because parameters passed in through the command line are global, but then again I'm targeting just the csproj file.
Anyway that is what happens. So is there any way to pass in a msbuild command line parameter to change just the one AssemblyName property in the MyProj.Shell.csproj file?
解决方案You can edit your project in question (its .csproj file) to obtain assembly name from a special property if it is specified, i.e.:
<AssemblyName Condition=" '$(ThisProjectNameOverrideAssemblyName)' == '' " >UsualAssemblyName</AssemblyName> <AssemblyName Condition=" '$(ThisProjectNameOverrideAssemblyName)' != '' " >$(ThisProjectNameOverrideAssemblyName)</AssemblyName>
So when you build your project in question, you pass your
ThisProjectNameOverrideAssemblyName
to overrideAssemblyName
for this project only:msbuild /p:ThisProjectNameOverrideAssemblyName=NewAssemblyName
这篇关于Msbuild命令行参数在项目级别不解决方案级别更改AssemblyName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- The only difference between 1 & 2 is the