使用MSBuild时不构建私有访问器 [英] Private Accessor don't build when using MSBuild

查看:81
本文介绍了使用MSBuild时不构建私有访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的构建服务器使用MSBuild来构建我的应用程序.我们的单元测试要求访问某些私有成员进行测试,因此我们使用内置的私有访问器. Visual Studio没问题,但是当我们将代码推送到生成服务器时,会出现错误:

My build server uses MSBuild to build my application. Our unit tests require access to some private members for testing, so we use the built in private accessors. Visual Studio has no problem with it, but when we push our code to the build server we get the error:

MyTest.cs(96,13):错误CS0246: 类型或名称空间名称"My_Accessor" 找不到(您是否想念一个 使用指令或程序集 参考?)

MyTest.cs (96,13): errorCS0246: The type or namespace name 'My_Accessor' could not be found (are you missing a using directive or an assembly reference?)

为什么MSBuild会忽略私有访问者,我该如何解决?

Why is it that MSBuild ignores the private accessors and how can I fix it?

我们将NUnit用于我们的测试框架,并将CruiseControl.Net用于我们的持续集成服务器.

We use NUnit for our testing framework and CruiseControl.Net for our continuous integration server.

根据评论,这是存储库模式类的基类的一些测试代码.

As per the comment, here is some test code for the base class for a repository pattern class.

MockRepository mocks = new MockRepository();

IDataContextWrapper wrapper = mocks.DynamicMock<IDataContextWrapper>();

Repository_Accessor target = new Repository_Accessor(wrapper);
Assert.AreEqual(wrapper, target._DataContext);

此代码仅验证成员变量_DataContext是否设置为模拟包装.在我的构建服务器上使用MSBuild进行构建时,它会失败.

This code simply verifies that the member variables _DataContext is set to the mocked wrapper. It fails when building with MSBuild on my build server.

推荐答案

与Mehmet的回答一样,我担心唯一可以使它起作用的方法是安装Visual Studio.安装完成后,msbuild开始为我生产访问器.这不是理想的解决方案,但至少我可以继续.

As good as Mehmet's answer was, I'm afraid the only way I could get this to work was to install visual studio. Once this was installed, msbuild started to produce the accessors for me. Not an ideal solution but at least I can move on.

这篇关于使用MSBuild时不构建私有访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆