参考Microsoft.VisualStudio.QualityTools.UnitTestFramework for CI build [英] Reference Microsoft.VisualStudio.QualityTools.UnitTestFramework for CI build
问题描述
我在VS2015 RC中创建了一个C#测试项目.它在本地构建,但是当我尝试在我们的CI构建服务器(TeamCity)上构建时,它失败并显示以下错误:
I have created a C# test project in VS2015 RC. it builds locally but when i attempt to build on our CI build server (TeamCity) it fails with errors:
UnitTest1.cs(2,17):错误CS0234:类型或名称空间名称 "Microsoft"命名空间中不存在"VisualStudio"(您是 缺少程序集引用?) [... .Tests.csproj] UnitTest1.cs(9,10):错误CS0246:类型或名称空间名称 找不到"TestMethod"(您是否缺少using指令或 组装参考?) [... .Tests.csproj]
UnitTest1.cs(2,17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [... .Tests.csproj] UnitTest1.cs(9,10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?) [... .Tests.csproj]
很明显,这是因为包含这些名称空间(Microsoft.VisualStudio.QualityTools.UnitTestFramework
)的程序集不在生成服务器上;在我的本地计算机上,它位于C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
.
Clearly this is because the assembly containing these namespaces (Microsoft.VisualStudio.QualityTools.UnitTestFramework
) is not on the build server; on my local machine it resides at C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
.
我可以将程序集复制到我的解决方案中,从而使其成为代码库的一部分,但是手动移动文件感觉有点像是不雅的骇客.我在nuget上搜索,发现 http://www.nuget.org/我认为可以解决这个问题的packages/Microsoft.VisualStudio.QualityTools.UnitTestFramework/,但是安装该软件包失败:
I could copy the assembly into my solution so that it becomes part of the codebase but manually moving files feels like a bit of an inelegant hack. I searched around on nuget and found http://www.nuget.org/packages/Microsoft.VisualStudio.QualityTools.UnitTestFramework/ which I figured would do the trick, but installing that package failed with:
Install-Package:无法安装软件包 'Microsoft.VisualStudio.QualityTools.UnitTestFramework 11.0.50727.1'. 您正在尝试将此软件包安装到针对的项目中 '.NETFramework,版本= v4.5.2',但该软件包不包含任何 与之兼容的程序集引用或内容文件 框架
Install-Package : Could not install package 'Microsoft.VisualStudio.QualityTools.UnitTestFramework 11.0.50727.1'. You are trying to install this package into a project that targets '.NETFramework, Version=v4.5.2', but the package does not contain any assembly references or content files that are compatible with that framework
解决这个问题的最佳选择是什么?我很惊讶在VS2015中创建一个测试项目并不会自动包含我需要的所有依赖关系,尽管也许我很天真(我有点像个雏形的点网匠).
What's my best option of solving this? I'm surprised that creating a test project in VS2015 does not automatically include all the dependencies that I need, though perhaps I'm being naive (I'm something of a fledgling dot netter).
推荐答案
答案类似于通常位于 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
)
The answer is similar to option 1 in eng.augusto's answer.
Microsoft doesn't provide NuGet for the latest version of Microsoft.VisualStudio.QualityTools.UnitTestFramework,
but rather supplies it as a part of Visual Studio
(normally at C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
)
我创建了文件夹Microsoft.VisualStudio.QualityTools
作为解决方案的子文件夹并进行了复制:
I created the folder Microsoft.VisualStudio.QualityTools
as a subfolder of my solution and copied:
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll Microsoft.VisualStudio.QualityTools.UnitTestFramework.xml
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll Microsoft.VisualStudio.QualityTools.UnitTestFramework.xml
应将文件添加到源代码管理中(即使通常会忽略DLL).
然后,我将Test.csproj中的引用更改为引用新位置.
The files should be added to source control (even if DLLs are usually ignored).
Then I changed references in my Test.csproj to refer to a new location.
这篇关于参考Microsoft.VisualStudio.QualityTools.UnitTestFramework for CI build的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!