Stanislav Rataj
Stanislav Rataj

Reputation: 41

How to setup MSBuild to name Project.dll instead od Project.vcxproj.dll in TeamCity?

I've got a problem while using TeamCity automation build engine. I need to build many vcxprojects, some of them are LIB or DLL and rest are EXE files, using previously built LIBs.

Example of setting one LIB project in TeamCity is:

    <runner id="RUNNER_15" name="MP3" type="MSBuild">
      <parameters>
        <param name="build-file-path" value="Audio\mp3\mp3.vcxproj" />
        <param name="dotNetCoverage.NCover.HTMLReport.File.Sort" value="0" />
        <param name="dotNetCoverage.NCover.HTMLReport.File.Type" value="1" />
        <param name="dotNetCoverage.NCover.Reg" value="selected" />
        <param name="dotNetCoverage.NCover.platformBitness" value="x86" />
        <param name="dotNetCoverage.NCover.platformVersion" value="v2.0" />
        <param name="dotNetCoverage.NCover3.Reg" value="selected" />
        <param name="dotNetCoverage.NCover3.args" value="//ias .*" />
        <param name="dotNetCoverage.NCover3.platformBitness" value="x86" />
        <param name="dotNetCoverage.NCover3.platformVersion" value="v2.0" />
        <param name="dotNetCoverage.NCover3.reporter.executable.args" value="//or FullCoverageReport:Html:{teamcity.report.path}" />
        <param name="dotNetCoverage.PartCover.Reg" value="selected" />
        <param name="dotNetCoverage.PartCover.includes" value="[*]*" />
        <param name="dotNetCoverage.PartCover.platformBitness" value="x86" />
        <param name="dotNetCoverage.PartCover.platformVersion" value="v2.0" />
        <param name="msbuild_version" value="4.0" />
        <param name="run-platform" value="x86" />
        <param name="toolsVersion" value="4.0" />
      </parameters>
    </runner>

In case of DLL, linker setting in vcxproj file says: .\Release\$(ProjectName).dll In case of LIB there isn't such setting at all.

When I build it using VS2010 command line, output is .\Release\mp3.dll or .\Release\mp3.lib.

But when I use TC, I'll get output .\Release\mp3.vcxproj.dll or .\Release\mp3.vcxproj.lib

Why? How to avoid this strange behavior? (I don't want to replace line in vcxproj file like .\Release\mp3.dll, it's problem with many projects and I'd like to avoid this primitive solution and in case of LIB projects there is not such possibility at all)

Thx for any response.

Upvotes: 3

Views: 1077

Answers (2)

Alexey Biryukov
Alexey Biryukov

Reputation: 727

Here is a workaround for this issue that does not require changing anything in project files. Before any project build will be invoked, a script is executed that would rename all .vcxproj files of interest into files of the same name but without .vcxproj extension. It is a 'Command Line' runner and the script is

for /r directory\with_projects %%%%f in (*.vcxproj) do rename %%%%f %%%%~nf

Then 'Visual Studio' runner has the renamed project files as arguments. Internally the runner makes a copy with .teamcity extension, which in turn is trimmed by Visual Studio giving the correct $(ProjectName) value.

Upvotes: 0

Alan Spark
Alan Spark

Reputation: 8292

I had the same problem with .vcxproj appearing in the filename of my binaries. I narrowed it down to the $(ProjectName) variable being different when built with TeamCity than when I built it on my own machine.

The solution for me was to define the ProjectName variable in each of the affected project files (strangely it didn't seem to happen in certain types of projects, e.g. static libraries).

<!-- Define project name to avoid TeamCity from generating incorrect one -->
<PropertyGroup>
    <ProjectName>NAME_OF_PROJECT</ProjectName>
</PropertyGroup>

I put this below the <PropertyGroup Label="UserMacros" /> line and above the <TargetName> definitions which reference it.

I still don't understand why TeamCity is different... I hope this helps others with the same problem.

Upvotes: 1

Related Questions