0

技术:Visual Studio 2010、Visual Studio 可视化和建模 SDK

我们有一个商业的 Visual Studio 2010 DSL,当我们发布新版本时,我们希望增加版本号。我打开 DslDefinition.dsl 并根据需要更新版本号,然后执行转换所有模板以反映更改。DslPackage 'source.extension.vsixmanifest' 得到很好的更新并显示新的版本号。

然而问题是,当有人打开从版本 1.0.0.0 和更新版本 1.0.0.1 创建的模型时,他们无法打开模型,原因似乎是 *.diagram 文件中的“dslVersion”是设置为已过时的 1.0.0.0,我可以通过手动更新 dslVersion 来修复,但似乎无法设置支持的版本范围。

有什么解决办法吗?

4

1 回答 1

1

我通过覆盖位于“*SerializationHelper”类中的“CheckVersion”方法解决了这个问题。我的实现如下。

     partial class ProductSerializationHelper
    {
        protected override void CheckVersion(Microsoft.VisualStudio.Modeling.SerializationContext serializationContext, System.Xml.XmlReader reader)
        {
            #region Check Parameters
            global::System.Diagnostics.Debug.Assert(serializationContext != null);
            if (serializationContext == null)
                throw new global::System.ArgumentNullException("serializationContext");
            global::System.Diagnostics.Debug.Assert(reader != null);
            if (reader == null)
                throw new global::System.ArgumentNullException("reader");
            #endregion

            global::System.Version expectedVersion = new global::System.Version("2.5.0.0");
            string dslVersionStr = reader.GetAttribute("dslVersion");
            if (dslVersionStr != null)
            {
                try
                {
                    global::System.Version actualVersion = new global::System.Version(dslVersionStr);

// #### THIS IS WHERE I CHANGED FROM '!=' to '>'
                    if (actualVersion > expectedVersion)
                    {
                        ProductSerializationBehaviorSerializationMessages.VersionMismatch(serializationContext, reader, expectedVersion, actualVersion);
                    }
                }
                catch (global::System.ArgumentException)
                {
                    ProductSerializationBehaviorSerializationMessages.InvalidPropertyValue(serializationContext, reader, "dslVersion", typeof(global::System.Version), dslVersionStr);
                }
                catch (global::System.FormatException)
                {
                    ProductSerializationBehaviorSerializationMessages.InvalidPropertyValue(serializationContext, reader, "dslVersion", typeof(global::System.Version), dslVersionStr);
                }
                catch (global::System.OverflowException)
                {
                    ProductSerializationBehaviorSerializationMessages.InvalidPropertyValue(serializationContext, reader, "dslVersion", typeof(global::System.Version), dslVersionStr);
                }
            }
        }
    }
于 2010-11-29T11:06:41.830 回答