我正在使用 演练:第 1 部分 - 创建一个基本的项目系统 完全按照网站 http://msdn.microsoft.com/en-us/library/cc512961.aspx 和 项目管理包框架 完全按照从 http://mpfproj11.codeplex.com/ 下载的方式编写。我已经在 Visual Studio 2013 中的多台开发机器上测试了演练。我还在 Visual Studio 2010 和 2012 中使用各自的 SDK 进行了测试。在每个测试中都出现了同样的问题。
问题:我收到异常 - mscorlib.dll 中发生类型为“System.FormatException”的异常,但未在用户代码中处理附加信息: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 中的
<ProjectGuid>$guid1$</ProjectGuid>
。ProjectNode 类的 Load 方法中的断点显示
this.projectIdGuid = Guid.NewGuid();
返回一个新的 guid,例如 {6d4b8668-51ca-40eb-b013-9e7f96b82b68}。
在 ProjectNode 类的 Reload 方法中,方法
this.SetProjectGuidFromProjectFile()
被触发,然后抛出异常,如上所示。如果我在 SimpleProject.myproj 中取出 <ProjectGuid>$guid1$</ProjectGuid>
,我会毫无异常(exception)地访问该应用程序,但您将没有与该应用程序关联的 guid,并且如果尝试访问新创建的应用程序的属性页面,则会收到错误消息。 .myproj 可能没有正确注册?我花了一周时间通过各种博客和论坛研究这个主题。 最佳答案
问题来自 MPF(这是一段严重的蹩脚代码 - 不幸的是,它是唯一可用的完整示例)实现了自定义模板参数替换过程(此处描述的 Visual Studio 特定过程: http://msdn.microsoft.com/en-us/library/eehb4faa.aspx )仅支持替换所有项目(子)项,但不支持替换项目项本身。因此,您不能在 xxxx.myproj 文件中使用 $guid1$ 或任何其他 $thingy$。
正如您所发现的,最简单的方法是删除此 $guid1$ 参数,并将其留空,因为 MPF 确实支持空白参数:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
...
<ProjectGuid></ProjectGuid>
...
</PropertyGroup>
...
</Project>
现在,与您的信念相反:) 这很好用。这将设置 ProjectIDGuid ProjectNode 的属性。
您也在追求的属性页面是一个完全不同的野兽。为简化起见,Visual Studio 将查询 __VSHPROPID2.VSHPROPID_PropertyPagesCLSIDList 属性的层次结构。默认情况下,强积金是这样实现的:
/// <summary>
/// List of Guids of the config independent property pages. It is called by the GetProperty for VSHPROPID_PropertyPagesCLSIDList property.
/// </summary>
/// <returns></returns>
protected virtual Guid[] GetConfigurationIndependentPropertyPages()
{
return new Guid[] { Guid.Empty };
}
Guid.Empty 是一个糟糕的选择(他们可以只发送一个空数组),因为它会引发以下错误,这很难用我们不知道它来自哪里的标准空 guid 进行诊断:
因此,您需要做的是覆盖 GetConfigurationIndependentPropertyPages 并为其提供另一个 Guid,该 Guid 对应于从 SettingsPage 等派生的类,但这是另一回事。
关于c# - 在 VS 可扩展性演练中,Guid 应包含 32 位数字和 4 个破折号 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23959642/