Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change assembly name for build settings in .csproj

I have an application which I want to publish with ClickOnce via command line. I have a test and a live version. It should be allowed to have both installed at the same time, which means that I need to change the assemble name (and preferably also the product name) for one of the builds. I would like to do this in the build settings.

I have managed to make some build settings, which works fine, but I cannot figure out how to change the assembly and product name, for just one of them.

I have added the following code to my .csproj file, which I call with the command msbuild /target:Test or msbuild /target:Live. But where do I implement the assembly and product name change?

<PropertyGroup>
  <ProjLocation>$(ProjectDir)</ProjLocation>
  <ProjLocationReleaseDir>$(ProjLocation)\bin\Debug</ProjLocationReleaseDir>
  <ProjPublishLocation>$(ProjLocationReleaseDir)\app.publish</ProjPublishLocation>
  <DeploymentFolder>C:\MyProjects\Software\Publish\</DeploymentFolder>
</PropertyGroup>

<!-- Build settings for live version -->
<Target Name="Live" DependsOnTargets="Clean">

  <MSBuild Projects="$(ProjLocation)\$(ProjectName).csproj"
    Properties="$(DefaultBuildProperties)"
    Targets="Publish"/>

  <ItemGroup>
    <SetupFiles Include="$(ProjPublishLocation)\*.*"/>
    <UpdateFiles Include="$(ProjPublishLocation)\Application Files\**\*.*"/>
  </ItemGroup>


  <Copy SourceFiles="@(SetupFiles)" DestinationFolder="$(DeploymentFolder)\Live\" />
  <Copy SourceFiles="@(UpdateFiles)" DestinationFolder="$(DeploymentFolder)\Live\Application Files\%(RecursiveDir)"/>
</Target>

<!-- Build settings for test version -->
<Target Name="Test" DependsOnTargets="Clean">

  <MSBuild Projects="$(ProjLocation)\$(ProjectName).csproj"
    Properties="$(DefaultBuildProperties)"
    Targets="Publish"/>

  <ItemGroup>
    <SetupFiles Include="$(ProjPublishLocation)\*.*"/>
    <UpdateFiles Include="$(ProjPublishLocation)\Application Files\**\*.*"/>
  </ItemGroup>


  <Copy SourceFiles="@(SetupFiles)" DestinationFolder="$(DeploymentFolder)\Public Test\" />
  <Copy SourceFiles="@(UpdateFiles)" DestinationFolder="$(DeploymentFolder)\Public Test\Application Files\%(RecursiveDir)"/>
</Target>
like image 568
Jakob Busk Sørensen Avatar asked Nov 16 '25 11:11

Jakob Busk Sørensen


1 Answers

You can add "AssemblyName" property to the PropertyGroup. like this:

<PropertyGroup>
  <AssemblyName>YourAppName</AssemblyName>
</PropertyGroup>

or you can use the MSBuild command line switch. like this :

msbuild /property:AssemblyName=YourAppName
like image 187
nizhenghua Avatar answered Nov 18 '25 19:11

nizhenghua



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!