Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Here's how to migrate your custom check-in policies in Team Foundation Version Control (TFVC). You can update code, you can use a predefined method for further automigration, and you can use a workaround to remove obsolete policies.
Important
Complete the migration steps before you delete your existing policies.
Code updates
To migrate your custom policies:
Create a new class with the same methods, but inheriting the
CheckinPolicyBaseclass (IPolicyCompatibilityJsonforIPolicyCompatibility) instead of thePolicyBaseclass.Here's an obsolete example.
[Serializable] public class Simple : PolicyBase { public override string Description => "SimplePolicyDescription"; ... }Here's an updated example.
[Serializable] public class SimpleNew : CheckinPolicyBase { public override string Description => "SimplePolicyDescription"; ... }If
GetBinaryFormatterwas overridden, also implementGetJsonSerializerSettings. Use the same serialization logic. ConfigureJsonSerializerSettings, withTypeNameHandlingset toObjects.Here's an obsolete example.
[Serializable] public class Simple : PolicyBase { public override BinaryFormatter GetBinaryFormatter() { BinaryFormatter formatter = new BinaryFormatter(); formatter.Binder = new SimpleBinder(); return formatter; } ... }Here's an updated example.
[Serializable] public class SimpleNew : CheckinPolicyBase { public override JsonSerializerSettings GetJsonSerializerSettings() { return new JsonSerializerSettings() { SerializationBinder = new SimpleNewSerializationBinder(), TypeNameHandling = TypeNameHandling.Objects }; } ... }For extensions that target Visual Studio version 16 and earlier, the following extra code is required, even if
BinaryFormatterwasn't previously overridden.public class CheckinSerializationBinder : ISerializationBinder { public void BindToName(Type serializedType, out string assemblyName, out string typeName) { Assembly assembly = serializedType.Assembly; assemblyName = assembly.FullName; typeName = serializedType.FullName; } public Type BindToType(string assemblyName, string typeName) { throw new NotImplementedException(); } } [Serializable] public class SimpleNew : CheckinPolicyBase { public override JsonSerializerSettings GetJsonSerializerSettings() { return new JsonSerializerSettings() { SerializationBinder = new CheckinSerializationBinder(), TypeNameHandling = TypeNameHandling.Objects }; } ... }In the new policy type, skip private properties that were previously serialized. Add
[JsonProperty]to ensure they're saved to the database.For example:
[Serializable] public class SimpleNew : CheckinPolicyBase { [JsonProperty] private List<String> pathFilters; ... }Replace legacy policy-loading APIs.
For example, the following legacy methods are obsolete:
GetCheckinPoliciesForServerPaths,GetCheckinPolicies, andSetCheckinPolicies. Use the following methods from the package, accordingly:GetCheckinClientPoliciesForServerPaths,GetCheckinClientPolicies, andSetCheckinClientPolicies.Automatic policy migration is supported only for custom policies. Built-in Visual Studio policies support the new policy model and migration.
Use a predefined method to migrate policies on server
Further automigration is available only for custom policies. Standard Visual Studio policies don't support this capability. If you don't plan to use the migration method provided by a NuGet package, you can skip this section and proceed to the next section in this article.
Add the
IPolicyMigrationinterface for each obsolete custom policy. This interface is deprecated and slated for removal in a future release along withPolicyBaseandIPolicyCompatibility.Important
Obsolete policies that don't inherit this interface are skipped during migration. They're not saved as new policies.
Implement the
ToNewPolicyTypemethod on the obsolete policy. This method must:- Return an instance of the new policy class.
- Populate the new instance with values from the obsolete policy.
For example:
[Serializable] public class Simple : PolicyBase, IPolicyMigration { ... public CheckinPolicyBase ToNewPolicyType() { return new SimpleNew(); } }Call the
MigrateFromOldPoliciesmethod.