Sergey Metlov
Sergey Metlov

Reputation: 26331

Specify build directory name

I need project to be built into folder:

\bin\Debug 1.0.3.4

Where 1.0.3.4 is a current building assembly version specified in assembly: AssemblyVersion attribute.
I tried using different variables like $(AssemblyVersion), GetAssemblyIdentity task but had no luck.. I'm not so good at using MSBuild.

Upvotes: 1

Views: 463

Answers (1)

makhdumi
makhdumi

Reputation: 1328

A quick and dirty solution to this is to, after the build, use GetAssemblyIdentity to extract the version info and then move the $(TargetFile) to the appropriate directory.

This assumes you don't have any dependencies going on. Otherwise, you'll need to modify the $(TargetPath), $(TargetName), and $(TargetExt) or go with the "proper" way of doing it - modifying $(OutputPath) dynamically.

  <Target Name="AfterBuild" AfterTargets="Build">
    <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
      <Output TaskParameter="Assemblies" ItemName="AssemblyIdentity"/>
    </GetAssemblyIdentity>
    <PropertyGroup>
      <Version>@(AssemblyIdentity->'%(Version)')</Version>
    </PropertyGroup>
    <Copy SourceFiles="$(TargetPath)" DestinationFolder="$(OutDir)$(Version)" />
  </Target>

The proper way would be to modify $(OutDir) aka $(OutputPath), but that would involve things like modifying the AssemblyVersion.cs file (or more complexly, a copy of it injected automatically into the build chain).

You could also instead parse the version from the AssemblyVersion.cs file.

Upvotes: 1

Related Questions