关于"The dependency was added by the project system and cannot be removed" Error

时间:2023-03-09 05:22:21
关于"The dependency was added by the project system and cannot be removed" Error

阅读一个简单地工程代码,其中一个工程BaseCode是 static lib,另一个工程RunBaseCode使用该lib,但在工程设置的“Linker\Input\AdditionalDependencies” 中并没有添加对该lib的引用,而在“Linker\Command Line”中却发现BaseCode.lib已经添加进来了,这是怎么回事呢?

首先怀疑是Solution中设置的 “Project Dependencies”编译依赖,隐含的添加了lib,因此想把RunBaseCode对BaseCode的依赖去掉试试看。取消依赖时,却发现取消不了,出现"The dependency was added by the project system and cannot be removed" 错误。那这个编译依赖是在哪里添加的呢?

关于"The dependency was added by the project system and cannot be removed" Error

原来是在“Project References”中设置的。

右键\Properties\Common Properties\Framework and References\Add New Reference。

关于"The dependency was added by the project system and cannot be removed" Error

设置Reference后,该工程就自动加上了“Project Dependencies”。

那默认添加对BaseCode.lib的引用,是否是由于设置了“Project Dependencies”呢?不是的,是由于上面所述的设置“Reference”导致的。验证的情况如下:

1. 点击“Remove Reference”去掉工程关联后,默认的“Project Dependencies”也取消掉了。这时,手动添加“Project Dependencies”,发现“Linker\Command Line”中没有自动添加BaseCode.lib。

2. 将上一步骤中的“Project Dependencies”去掉,然后“右键\Properties\Common Properties\Framework and References\Add New Reference”,这时“Linker\Command Line”中自动添加了BaseCode.lib。

References

【1】Error while removing project dependency in VS2010 (http://*.com/questions/12818315/error-while-removing-project-dependency-in-vs2010)

【2】VS项目依赖(http://www.cppblog.com/mythma/archive/2011/08/05/this_dependency_was_added_by_the_project_system_and_cannot_be_removed.html