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 に答える