Msbuild command line argument at project-level not

2019-02-15 10:24发布

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条回答
劫难
2楼-- · 2019-02-15 10:46

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
查看更多
登录 后发表回答