2

In visual studio when you add a reference to an existing project in your solution in the .csproj file it ends up like so:

<ProjectReference Include="..\TestProject2\TestProject2.csproj">
  <Project>{15EC8369-B0C5-4F71-A366-19042F450A2D}</Project>
  <Name>TestProject2</Name>
</ProjectReference>

If I add a reference to an assembly DLL via EnvDTE:

var p = _project as VsProject;
p.References.Add(<path to assembly DLL>);

it ends like this:

<Reference Include="TestProject2.csproj">
  <HintPath>..\TestProject2\bin\Debug\TestProject2.csproj.dll</HintPath>
</Reference>

This is not so great because if I switch to a Release build it will still reference the debug assembly. Another problem is that I have to build the referenced assembly before I can add it as a reference. With Visual Studio UI I can add a reference to an unbuilt project.

Is it possible via the EnvDTE API to add a project reference?

I know I can manipulate the .csproj file as an XML document and do whatever I want, but since I started on the path on EnvDTE I would prefer to stick to it.

2 Answers 2

6

It looks like the References interface has an AddProject method which handles project-to-project refrences.

Sign up to request clarification or add additional context in comments.

2 Comments

I believe you can also add a reference to a project with Add.References by supplying the project name. see blogs.msdn.com/b/murat/archive/2008/07/30/…
Getting this error. msdn.microsoft.com/en-us/library/ms228768(v=vs.110).aspx Tried the solution still couldn't make that work.
0

What worked for me is to formulate references this way:

<Reference
  Include="MyDll"
  Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
  <HintPath>..\..\somePath\Debug\myDll.dll</HintPath>
</Reference>
<Reference
  Include="MyDll"
  Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
  <HintPath>..\..\somePath\Release\myDll.dll</HintPath>
</Reference>

This way, the release build references release dependency, and debug build references Debug. Of course, x86/x64 can also be handled if necessary. This was for a 32-bit app.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.