在调试模式下,.dll引用可以正确加载到C#项目中,但在发布模式下找不到命名空间。

6
我正在为公司建立一个CI服务器并集成单元测试。我选择使用TeamCity和NUnit,因为它们在我以前工作的其他组织中表现良好。目前,我已经成功地安装了TeamCity,并且创建了一个单元测试项目来验证TeamCity是否正确处理了我的NUnit配置。在我的项目中,我添加了对nunit.framework.dll的引用,它位于解决方案根目录下的一个文件夹中。当我提交解决方案进行测试时,我从TeamCity的构建步骤中得到了以下输出:
[10:45:35][Csc] UnitTesting.cs(5, 7): error CS0246: The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?)

[10:45:35][Csc] UnitTesting.cs(16, 10): error CS0246: The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)

[10:45:35][Csc] UnitTesting.cs(16, 10): error CS0246: The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)

[10:45:35][Csc] UnitTesting.cs(13, 6): error CS0246: The type or namespace name 'TestFixture' could not be found (are you missing a using directive or an assembly reference?)

[10:45:35][Csc] UnitTesting.cs(13, 6): error CS0246: The type or namespace name 'TestFixtureAttribute' could not be found (are you missing a using directive or an assembly reference?)

当我回到我的IDE时,我能够构建解决方案,而不会看到那些错误消息。直到我切换到发布配置。当我切换配置并构建解决方案时,我从TeamCity获得的相同消息在我的IDE中出现了。
我尝试再次将.dll文件添加到我的项目中,但Visual Studio抱怨参考已经存在,并阻止我再次添加它。
怎么回事?

2
尝试删除引用,然后重新添加引用。 - Robert Snyder
这个问题也可能发生在从NuGet安装的项目中。卸载和重新安装包可以修复错误。 - CodyF
我当时没有使用NuGet,但现在知道了。 - Brandon
1个回答

12

基本上这里发生的情况是:Visual Studio无缘无故地失去了与现实的联系,不知道在哪里查找.dll文件。我不知道为什么它只会在Release配置中发生,但我删除了引用并重新添加了它,一切都很好。


1
我在我的一个项目中也遇到了同样的问题。这是解决它的方法。谢谢! - Kevin Lee Garner

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接