在VS可扩展性演练中,Guid应包含32位数字和4个破折号(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

我正在使用演练:第1部分 – 创建一个基本项目系统,完全按照网站http://msdn.microsoft.com/en-us/library/cc512961.aspx编写,完全从下载的项目管理包框架 http://mpfproj11.codeplex.com/ 。 我已经在Visual Studio 2013中测试了多个开发机器上的演练。我还使用各自的SDK在Visual Studio 2010和2012中对此进行了测试。 在每个测试中都要遵循相同的问题。

问题:我收到exception – mscorlib.dll中发生类型’System.FormatException’的exception,但未在用户代码中处理附加信息:Guid应包含32位数字和4个破折号(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx )在ProjectNode类方法中:

private void SetProjectGuidFromProjectFile() { string projectGuid = this.GetProjectProperty(ProjectFileConstants.ProjectGuid); if (String.IsNullOrEmpty(projectGuid)) { this.projectIdGuid = Guid.NewGuid(); } else { Guid guid = new Guid(projectGuid); if (guid != this.projectIdGuid) { this.projectIdGuid = guid; } } } 

Guid guid = new Guid(projectGuid);

projectGuid返回字符串“$ guid1 $”,它来自SimpleProject.myproj中的$guid1$

ProjectNode类的Load方法中的断点显示了这一点

 this.projectIdGuid = Guid.NewGuid(); 

返回一个新的指南,例如{6d4b8668-51ca-40eb-b013-9e7f96b82b68}。

在ProjectNode类的Reload方法中,触发this.SetProjectGuidFromProjectFile()方法然后抛出exeption,如上所示。 如果我在SimpleProject.myproj中取出$guid1$ ,我会毫无例外地进入应用程序,但是你没有与应用程序关联的guid,并且如果试图访问属性页面将会收到错误新创建的应用程序。 .myproj可能无法正确注册? 我花了一周时间通过各种博客和论坛研究这个主题。

问题来自于MPF(这是一个非常糟糕的代码片段 – 不幸的是,它是唯一可用的完整示例)实现了一个自定义模板参数替换过程(这里描述的Visual Studio特定的过程: http:// msdn.microsoft.com/en-us/library/eehb4faa.aspx )仅支持替换所有项目(子)项目,但不支持项目项目本身。 因此,您不能在xxxx.myproj文件中使用$ guid1 $或任何其他$ thingy $。

正如您所发现的,最简单的方法是删除此$ guid1 $参数,并将其留空,因为MPF支持空白:

   ...  ...  ...  

现在,与你的信念相反:)这很好用。 这将设置ProjectIDGuid ProjectNode的属性。

你追求的属性页面是一个完全不同的野兽。 为简化起见,Visual Studio将在层次结构中查询__VSHPROPID2.VSHPROPID_PropertyPagesCLSIDList属性。 默认情况下,MPF实现如下:

  ///  /// List of Guids of the config independent property pages. It is called by the GetProperty for VSHPROPID_PropertyPagesCLSIDList property. ///  ///  protected virtual Guid[] GetConfigurationIndependentPropertyPages() { return new Guid[] { Guid.Empty }; } 

Guid.Empty是一个糟糕的选择(他们可能只发送一个空数组),因为它会引发以下错误,这很难用标准的空guid诊断我们不知道它来自哪里:

在此处输入图像描述

所以,你需要做的是覆盖GetConfigurationIndependentPropertyPages并给它另一个Guid,它对应于一个派生自SettingsPage等的类,但这是另一个故事。