简体   繁体   English

Visual Studio 2008:找不到对项目的引用

[英]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: 解决此问题的一种方法:

  1. Define an environment variable SOURCE_PATH that holds the path to your sources root folder 定义一个环境变量SOURCE_PATH,该变量保存到您的源根文件夹的路径
  2. Edit the project files so they have reference relative to this path (use $(SOURCE_PATH) ) in csproj files to reference it 编辑项目文件,以便它们在cproj文件中具有相对于此路径的引用(使用$(SOURCE_PATH) )来引用它
  3. Repeat steps 1-2 on each dev/build machine and add extra env variables if needed. 在每台开发/构建机器上重复步骤1-2,并在需要时添加额外的env变量。

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.

相关问题 Visual Studio 2008中C#项目中的C ++项目引用 - C++ project reference in a C# project in visual studio 2008 在 Visual Studio 中找不到正确的项目 - Cannot find right project in Visual Studio Visual Studio 2008 / C#:如何在项目中找到死代码? - Visual Studio 2008 / C# : How to find dead code in a project? Visual Studio 2008安装项目 - Visual Studio 2008 Setup Project Visual Studio 2017错误:无法找到项目信息“”这可能表示缺少项目参考 - 使用Console App .NET Core 2.1 - Visual Studio 2017 error: Cannot find project info for “” This can indicate a missing project reference - with Console App .NET Core 2.1 在Visual Studio中的“项目”-&gt;“添加引用”-&gt;“ COM”下找不到Microsoft Excel XX.Y对象库 - cannot find Microsoft Excel XX.Y Object Library under Project->Add Reference->COM in visual studio 如何将Visual Studio 2013项目降级为Visual Studio 2008项目? - How to downgrade a Visual Studio 2013 project to a Visual Studio 2008 project? Visual Studio 2008显式参考错误 - Visual Studio 2008 Explicit Reference Error Visual Studio模板上的项目参考 - Project Reference on Visual Studio Template 在Visual Studio中引用项目“readonly”? - Reference project “readonly” in Visual Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM