Question

I have a solution and three projects inside that which is all created dynamically. Now I have to add the first project's reference to the second and third one. When i tried the logic i'm able to build the project individually and when building the solution it throws me the "Reference could not be loaded properly" error. This happens when the .dll is added directly using theVSProject.References.Add() method.

So i tried of using the below code to which is posted as a solution to the above issue. But still i'm getting some error.

Imports VSLangProj
' Add the second project as a reference to the first project.
Sub AddProjectExample()
   ' First project is a Visual Basic or C# project.
   Dim theVSProject As VSProject = _
      CType(DTE.Solution.Projects.Item(1).Object, VSProject)

   ' Second project is any type of project.
   Dim secondProject As Project = DTE.Solution.Projects.Item(2)

   ' AddProject returns the newly created Reference object.
   Dim newReference As Reference
   newReference = theVSProject.References.AddProject(secondProject)
End Sub

The error is,

The referenced assembly 'EnvDTE, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be found. 

Any solution for this?

We don't have permission for VS IDE folder for applying the below fix.

Note: Have also tried the below solution for application App.Config but still there is issue.

msdn

Was it helpful?

Solution

NWard is absolutely right. Not sure about the code you're trying to use to add the references but the csproj file in the project root can be edited programmatically to add the following in its rightful place:

<ItemGroup>
    <ProjectReference Include="..\MyOtherProj\MyOtherProj.csproj">
      <Project>{abda85bb-2019-4b80-982e-b90add3fcca0}</Project>
      <Name>MyOtherProj</Name>
    </ProjectReference>
  </ItemGroup>

Call an internally invoked powershell script or some console exe. Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top