Change AssemblyName of a csproject via msbuild

2019-09-03 12:37发布

问题:

I have a msbuild that calls a *.sln file when doing compilation. This solution file contains 10 csprojects, one of them ( let's call it main.csproject) has the AssemblyName as WinMusic. The content of the msbuild is as follows:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">


  <PropertyGroup>
    <!-- Default value here -->
    <DefineConstants Condition=" '$(DefineConstants)'==''" >TRACE</DefineConstants>   
    <SlnFiles Condition=" '$(SlnFiles)'==''" >FullProject.sln</SlnFiles>   
  </PropertyGroup>

 <!-- <ItemGroup>  -->
  <!--   <SlnFiles Include="SlnFiles=$(SlnFiles2)"/> -->
  <!-- </ItemGroup> -->

  <Target Name="Build">
    <MSBuild Projects="$(SlnFiles)"
                 Properties="DefineConstants=$(DefineConstants)"/>
  </Target>

</Project>

My question is, how to set the AssemblyName property from the above msbuild task?

Just to clarify, I'm talking about AssemblyName in csproject, not in AssemblyInfo.cs.

Edit: This is the new build.proj file I tried, the FullProject.sln is a solution file with one exe and one dll, but the msbuild file renamed both the dll and the exe to NoMusic. What I want is just to rename the exe to NoMusic and the dll should retain the same name.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">


  <PropertyGroup>
    <!-- Default value here -->
    <DefineConstants Condition=" '$(DefineConstants)'==''" >TRACE</DefineConstants>   
    <SlnFiles Condition=" '$(SlnFiles)'==''" >FullProject.sln</SlnFiles>   
  </PropertyGroup>


  <Target Name="Build">
    <MSBuild Projects="$(SlnFiles)"
                 Properties="DefineConstants=$(DefineConstants)"/>

     <MSBuild Projects="WindowsFormsApplication1\WindowsFormsApplication1.csproj" 
         Properties="DefineConstants=$(DefineConstants);Platform=ANYCPU;AssemblyName=NoMusic"/>
  </Target>

</Project>

回答1:

Just do this:

<Target Name="Build">
    <MSBuild Projects="@(SlnFiles)"
             Properties="DefineConstants=$(DefineConstants)"/>

    <MSBuild Projects="main.csproject.csproj" 
         Properties="AssemblyName=NoMusic"/>

Love to know why though.



标签: msbuild