开发者

Visual Studio 2008: Cannot find reference to a project

We have an application wrote in C#, which broken into several projects. 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. 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.

Since `suo' file keeps absolute path to references, we cannot commit it in our source control.

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. (automation tool cleans everything, and get the latest version of the source again, so it dose not have `suo' file.)

Any solution?

Extra information

Visual Studio version: 2008 - 9.0.21022.8

.Net framework: 3.5 SP1

OS: Windows XP Professional (SP2 & SP3 - we have both of them)

Update

Seems that Visual Studio changes <ProjectReference&g开发者_如何学Got; tag to <Reference> in `.csproj' files sometimes. Our developers commit the file, and this problem happens.

I couldn't find if it's a bug in 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.


References are defined in the .csproj file for each project. 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". After you 're done editing, right click again and reload the project.


Open the project files (*.csproj) and look what are they referencing. 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
  2. Edit the project files so they have reference relative to this path (use $(SOURCE_PATH)) in csproj files to reference it
  3. Repeat steps 1-2 on each dev/build machine and add extra env variables if needed.

PS: The *.suo should not be in the version control system.


Why won't you use msbuild rather then automated visual studio compiler?


It's a bug in VisualStudio 2008 and before that.

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.

This bug is fixed in VS2010, and MSBuild 4.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜