dslversion-インクリメントする方法は、古いバージョンをサポートする方法は?
-
29-09-2019 - |
質問
技術: :Visual Studio 2010、Visual Studioの視覚化とモデリングSDK
商用Visual Studio 2010 DSLがあります。新しいバージョンをリリースすると、バージョン番号を増やす必要があります。 dsldefinition.dslを開き、必要に応じてバージョン番号を更新し、変更が反映されるようにすべてのテンプレートを変換します。 dslpackage 'source.extension.vsixmanifest'が正常に更新され、新しいバージョン番号が表示されます。
しかし、問題は、誰かが更新されたバージョン1.0.0.1でバージョン1.0.0.0から作成されたモデルを開くと、モデルを開くことができないため、 *.diagramファイルの「dslversion」が時代遅れの1.0.0.0に設定すると、DSLVersionを手動で更新することで修正できますが、サポートされているバージョンの範囲を設定する方法はないようです。
これに対する修正はありますか?
解決
「*SerializationHelper」クラスにある「チェックバージョン」メソッドをオーバーライドすることにより、この問題を解決しました。私の実装は以下にあります。
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);
}
}
}
}
所属していません StackOverflow