lysergic-acid
lysergic-acid

Reputation: 20050

How to avoid copying references assemblies and be able to run unit tests

I am using TeamCity to build a .NET product.

I'd like to take all of the solution(s) outputs and gather them under a single folder.

In order to do so, i'd like to set CopyLocal to false for all projects, so that when i copy */.dll it will not copy redundant files.

We have a big .sln file with projects, most of them are referencing our API assembly, and some are inter-referencing other projects from the solution.

While this is OK for debugging, i'd like to be able to pickup ONLY each project's output and copy it to some folder after build succeeds, without copying the referenced files into that folder as well.

At the same time, when dropping the referenced files from being copied, running unit tests doesn't work on the build server, since some of them require references assemblies.

I can't seem to get my head around it to fix this issue, without perhaps running the build twice (one for running tests, the other for actually getting a "clean" set of folders to copy from).

Any suggestions for managing such a build ?

Upvotes: 0

Views: 345

Answers (1)

Siy Williams
Siy Williams

Reputation: 2446

I'm not sure what your actually using to run your builds. Are you using a build script like msbuild or nant? or using the built in TeamCity build steps?

If you're using MsBuild then you can get the path of all compiled assemblies using the following:

<MSBuild Projects="@(Solutions)" Targets="Rebuild">
  <Output ItemName="Outputs" TaskParameter="TargetOutputs"/>
</MSBuild>    

Outputs will now contains the full path to each assembly. This means that you can now add an extra step to copy these files elsewhere for storage, or you can delete all other unwanted files (e.g clean) after you have run your unit tests e.g.

<CreateItem Include="$(BuildOutputDir)\**\*.*" Exclude="@(Outputs)">
  <Output TaskParameter="Include" ItemName="FilesToClean"/>
</CreateItem>

<Delete Files="@(FilesToClean)" />

I can't test the above as I'm not at my dev machine but hope that helps

Upvotes: 1

Related Questions