Msbuild command line argument at project-level not solution-level for changing AssemblyName

﹥>﹥吖頭↗ 提交于 2019-11-30 08:44:10

问题


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?


回答1:


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 override AssemblyName for this project only:

msbuild /p:ThisProjectNameOverrideAssemblyName=NewAssemblyName


来源:https://stackoverflow.com/questions/15553524/msbuild-command-line-argument-at-project-level-not-solution-level-for-changing-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!