简体   繁体   中英

Visual Studio 2012/2013 crashes when creating a new custom project type or when closing

I am trying to create a custom language service for Visual Studio 2012/2013 (there doesn't seem to be much of a difference between these two). The custom language service is for a compiler that has yet not been integrated into Visual Studio. I started by creating a Visual Studio package for my custom project type. It all works fine, but when I create a new project in Visual Studio it crashes. Sometimes it only crashes when I close Visual Studio. I always get a COMException with no other hint to the problem. I think there is nothing wrong with my Visual Studio package but rather with my custom project file. It builds fine when I use MSBUILD but Visual Studio doesn't like it for some reason. I heard there are other people who had the same problem and it always had something to do with the custom project file. Unfortunately there is very little documentation on that topic.

I am using the ProjectPackage of MPF to implement my package:

[ProvideProjectFactory(typeof(MyProjectFactory), null, "My Project Files (*.myproj);*.myproj", "myproj", "myproj", @"Templates\Projects", LanguageVsTemplate = "My Project")]
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid(GuidList.ProjectPackageGuidString)]
public sealed class MyProjectPackage : ProjectPackage
{
    public MyProjectPackage()
    {
        Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
    }

    protected override void Initialize()
    {
        base.Initialize();
        this.RegisterProjectFactory(new MyProjectFactory(this));
    }

    public override string ProductUserContext
    {
        get { return string.Empty; }
    }
}

This is what my project factory looks like:

[Guid(GuidList.ProjectFactoryGuidString)]
public class MyProjectFactory : ProjectFactory
{
    public MyProjectFactory(Package package)
        : base(package)
    {
        this.package = package;
    }

    private Package package;

    protected override ProjectNode CreateProject()
    {
        MyProjectNode project = new MyProjectNode(this.package);
        project.SetSite((IOleServiceProvider)((IServiceProvider)this.package).GetService(typeof(IOleServiceProvider)));
        return project;
    }
}

And this is my custom project node:

public class MyProjectNode : ProjectNode
{
    public MyProjectNode(Package package)
    {
        this.package = package;
    }

    private Package package;

    public override Guid ProjectGuid
    {
        get { return new Guid(GuidList.ProjectFactoryGuidString); }
    }

    public override string ProjectType
    {
        get { return "My Project"; }
    }

    public override void AddFileFromTemplate(string source, string target)
    {
        this.FileTemplateProcessor.AddReplace("$Title$", Path.GetFileNameWithoutExtension(target));

        this.FileTemplateProcessor.UntokenFile(source, target);
        this.FileTemplateProcessor.Reset();
    }
}

And this is my custom project file. I stripped it down to the bare minimum in order to locate the problem, but that didn't help:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>454501B3-90E2-4735-ABDF-27B77BEBFD7A</ProjectGuid>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Program.my" />
  </ItemGroup>
  <Target Name="Build">
    <Message Text="Hello, World!" />
  </Target>
</Project>

Does anybody have experience with this? I looked at the source code of the IronPython and IronRuby Visual Studio integration, but that is much too complex.

The problem is the use of method cascading when calling COM objects in the MPFProj source.

I was able to resolve this by modifying the GetActiveConfigurationName method, which is located at around line 431 of Dev12\\Src\\CSharp\\Utilities.cs. [ Note that I'm using the 2013 version of MPFProj downloaded from here: https://mpfproj12.codeplex.com ]

Change the following line:

EnvDTE.Configuration activeConfig = automationObject.ConfigurationManager.ActiveConfiguration;

to this:

EnvDTE.ConfigurationManager configManager = automationObject.ConfigurationManager; EnvDTE.Configuration activeConfig = configManager.ActiveConfiguration;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM