简体   繁体   中英

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 ?

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 (eg clean) after you have run your unit tests eg

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM