0

How can I change AssemblyName dynamically, based on content of some file?

For instance, I have file named "AssemblyBaseName.txt" which contains "Abcd" string I want my assembly DLL/EXE name to be Abcd.Common.dll, where "Common" is constant.

I've tried to use ReadLinesFromFile like this

  <Target Name="Build">
    <ItemGroup>
      <AssemblyBaseNameFile Include="Test.txt"/>
    </ItemGroup>
    <ReadLinesFromFile File="@(AssemblyBaseNameFile)">
      <Output TaskParameter="Lines" ItemName="AssemblyBaseName" />
    </ReadLinesFromFile>
    <Message Text="AssemblyBaseName: $(AssemblyBaseName)" />
  </Target>
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProductVersion>9.0.30729</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{FEE469DB-44BD-4CD9-BA08-91F1DFDE9679}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Common</RootNamespace>
    <AssemblyName Condition=" '$(AssemblyName)' == '' ">$(AssemblyBaseName).Common</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>

but did not succeed.

adontz
  • 1,338
  • 13
  • 32

1 Answers1

2

Since static properties are processed before any targets are executed, your target changed the value of $(AssemblyBaseName), but only after the value of the statically declared $(AssemblyName) was set – using the original value of $(AssemblyBaseName).

You need to redefine $(AssemblyName) dynamically (inside your target) as well.

Also, you've overridden the "Build" target. I'm not sure how this assembly will build, you need to use a differently named target, and be sure that it executes prior to any use of $(AssemblyName) by the normal build pipeline.

alexlomba87
  • 858
  • 2
  • 10
  • 26
Brian Kretzler
  • 9,226
  • 1
  • 29
  • 26