DSLVersion-如何增加但仍然支持旧版本?
-
29-09-2019 - |
题
技术: :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来解决,但似乎无法设置支持版本范围。
有什么解决方案吗?
解决方案
我已经通过覆盖“*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);
}
}
}
}
不隶属于 StackOverflow