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
Well, project references are helpful when you are building and testing in both debug and release mode. If you directly add a DLL then you are locked into whatever that particular DLL was built as. The project reference allows this to be a build time decision. This is correct what you are saying.
The easy way out: Create a shared library where you put in your shared code of P1 and P2. This shared project can be referenced by both P1 and P2.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With