[英]Visual Studio 2008: Cannot find reference to a project
We have an application wrote in C#, which broken into several projects. 我们有一个用C#编写的应用程序,它分为几个项目。 These projects have reference to others.
这些项目参考其他项目。
When someone gets the source from version control and opens the solution contains these projects on its own machine, Visual Studio cannot find the references between projects, even though referenced project is build successfully. 当有人从版本控制中获取源代码并打开解决方案时,即使在自己的计算机上包含这些项目的解决方案,Visual Studio也无法在项目之间找到引用,即使已成功构建了引用的项目。 That person have to re-add the reference to solve this.
该人必须重新添加引用以解决此问题。
Seems to me that Visual Studio keeps some data in `suo' file, so next time it knows where to find that re-added reference, and this problem won't appear next time the person opens the solution. 在我看来,Visual Studio在“ suo”文件中保留了一些数据,因此下次它知道在哪里可以找到该重新添加的引用,并且下次该人打开解决方案时,就不会出现此问题。
Since `suo' file keeps absolute path to references, we cannot commit it in our source control. 由于`suo'文件保留了引用的绝对路径,因此我们不能在源代码管理中提交它。
The problem is, We've got a separate machine, which builds this big application automatically (as our nightly-build releases) When the build-automation tool opens the solution, and calls Visual Studio's compiler to build it, the references cannot be find. 问题是,我们有一台单独的机器,该机器会自动构建这个大应用程序(如我们的夜间构建版本),当构建自动化工具打开解决方案并调用Visual Studio的编译器进行构建时,找不到引用。 (automation tool cleans everything, and get the latest version of the source again, so it dose not have `suo' file.)
(自动化工具会清除所有内容,并再次获取源的最新版本,因此它没有`suo'文件。)
Any solution? 有解决方案吗
Extra information 额外的信息
Visual Studio version: 2008 - 9.0.21022.8 Visual Studio版本:2008-9.0.21022.8
.Net framework: 3.5 SP1 .Net框架:3.5 SP1
OS: Windows XP Professional (SP2 & SP3 - we have both of them) 操作系统:Windows XP Professional(SP2和SP3-我们都有)
Update 更新
Seems that Visual Studio changes <ProjectReference>
tag to <Reference>
in `.csproj' files sometimes. 似乎Visual Studio有时会将.csproj文件中的
<ProjectReference>
标记更改为<Reference>
。 Our developers commit the file, and this problem happens. 我们的开发人员提交文件,然后发生此问题。
I couldn't find if it's a bug in Visual Studio. 我找不到它是否是Visual Studio中的错误。 The only solution that comes into my mind is to write a tool to correct this in `.csproj' files, before pass it to the automation tool.
我想到的唯一解决方案是在将其传递给自动化工具之前,编写一个工具来纠正.csproj文件中的错误。
References are defined in the .csproj
file for each project. 在每个项目的
.csproj
文件中定义了引用。 They may be defined in one of two ways (in my experience). 根据我的经验,可以用以下两种方式之一定义它们。
Either with a hint path to find the referenced assembly: 可以通过提示路径找到引用的程序集:
<Reference Include="CommonServiceLocator.NinjectAdapter, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\Dependencies\CommonServiceLocator.NinjectAdapter.dll</HintPath>
</Reference>
Or without one: 还是没有一个:
<Reference Include="CommonServiceLocator.NinjectAdapter, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL"/>
You need to make sure that the references are in the first form, that the hint path exists, and that it's a relative path so that it works no matter where you check out the solution. 您需要确保引用采用第一种形式,提示路径存在,并且它是相对路径,以便无论您在哪里签出解决方案都可以使用。
You can edit the .csproj
files either with an external editor, or by right clicking the project, choosing "Unload project" from the context menu, then right clicking again on the unloaded project and choosing "Edit projectname.csproj". 您可以使用外部编辑器来编辑
.csproj
文件,或者通过右键单击项目,从上下文菜单中选择“卸载项目”,然后再次右键单击已卸载的项目并选择“编辑projectname.csproj”。 After you 're done editing, right click again and reload the project. 完成编辑后,再次右键单击并重新加载项目。
Open the project files (*.csproj) and look what are they referencing. 打开项目文件(* .csproj),然后查看它们所引用的内容。 Mostly sure the paths are relative to the solution path and your build script might use other paths.
大多数情况下,请确保路径是相对于解决方案路径的,并且您的构建脚本可能会使用其他路径。
One way of solving this: 解决此问题的一种方法:
$(SOURCE_PATH)
) in csproj files to reference it $(SOURCE_PATH)
)来引用它 PS: The *.suo should not be in the version control system. PS:* .suo不应位于版本控制系统中。
为什么不使用msbuild而不是Visual Studio自动化编译器?
It's a bug in VisualStudio 2008 and before that. 这是VisualStudio 2008及之前的错误。
If you open a solution that contains a project that have reference to another project, but referenced project doesn't included in the solution, VS finds the referenced project, but changes the reference in a way that it refers to the output DLL, not the project itself. 如果您打开的解决方案中包含一个引用了另一个项目的项目,但是被引用的项目未包含在解决方案中,则VS会找到被引用的项目,但是会以引用输出DLL而不是引用DLL的方式更改引用。项目本身。
This bug is fixed in VS2010, and MSBuild 4. 此错误已在VS2010和MSBuild 4中修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.