简体   繁体   English

如何避免复制参考程序集并能够运行单元测试

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

I am using TeamCity to build a .NET product. 我正在使用TeamCity构建.NET产品。

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. 为此,我想将所有项目的CopyLocal设置为false,以便在我复制* / .dll时不会复制冗余文件。

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. 我们有一个很大的.sln文件,其中包含项目,大多数文件都引用了我们的API程序集,还有一些文件引用了该解决方案中的其他项目。

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? 您是否正在使用msbuild或nant之类的构建脚本? or using the built in TeamCity build steps? 或使用内置的TeamCity构建步骤?

If you're using MsBuild then you can get the path of all compiled assemblies using the following: 如果使用的是MsBuild,则可以使用以下命令获取所有已编译程序集的路径:

<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 我无法在开发机器上测试上述内容,但希望对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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