I have created a Visual Studio multi-project template in which one is a 'Shared' project, and another is a normal project for common 'Resources'. The other 5 normal projects each need to reference both the 'Shared' and the 'Resources' projects.
On a separate solution I then create a VISX extension to implement a wizard, but instead of pointing the .vsixmanifest Asset to "A project in current solution", I point to the .zip multi-project template I created.
My intent is to then use the vsix wizard to add the necessary project references. I've already done so with envDTE, and it works beautifully... mostly.
A reference to the 'Resources' project is added without a problem. The issue is when trying to add a "shared" project as a reference. I've tried using both the (Project) and the (Filename.shproj) arguments.
DTE VS = automationObject as DTE;
// This method is called after the solution is created.
public void RunFinished()
DTE VS = automationObject as DTE;
{
Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
Project sharedProj = null;
Project resourceProj = null;
List<Project> versionProjs = new List<Project>();
foreach (Project project in VS.Solution.Projects)
{
if (project.Name.Contains("Resources")) { resourceProj = project; }
else if (project.Name.Contains("Shared")) { sharedProj = project; }
else { versionProjs.Add(project); }
}
foreach (Project version in versionProjs)
{
// Add reference to shared project
VSProject vsProj = (VSProject)version.Object;
if (sharedProj != null)
{
// !!! Shared project should be added as a reference here, but it is causing a critical error. !!!
//BuildDependency bldDepends = VS.Solution.SolutionBuild.BuildDependencies.Item(version.UniqueName);
//bldDepends.AddProject(sharedProj.FileName);
//vsProj.References.Add(sharedProj.FileName);
//vsProj.References.AddProject(sharedProj);
}
// Add reference to the Resources project
if (resourceProj != null) { vsProj.References.AddProject(resourceProj); }
}
}
AddProject(Project) results in:
Exception thrown:'System.Runtime.InteropServices.COMException' in TemplateExtension.dll
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
AddProject(Filename.shproj) results in:
Exception thrown: 'System.Runtime.InteropServices.COMException' in TemplateExtension.dll
Please make sure that the file is accessible, and that it is a valid assembly or COM component.
EDIT 1
I have decided to make my project open to the public. The source code to this problem can be found here: https://github.com/theBIMdev/RevitExtension
The offending code specifically is in the Wizard.cs file. The commented out section represents 3 different attempts.
- Adding the project to the dependencies
- vsProj.References.Add(sharedProj.FileName);
- vsProj.References.AddProject(sharedProj);
EDIT 2
This problem has received some attention and been escalated by Microsoft here.