public static async void DoWorkInWriterLock(EnvDTE.Project project, IVsHierarchy hierarchy, Action<MsBuildProject> action) { await DoWorkInWriterLock((IVsProject)hierarchy, action); var fileSystem = new PhysicalFileSystem(@"c:\"); fileSystem.MakeFileWritable(project.FullName); project.Save(); }
private static async Task DoWorkInWriterLockInternal(Project project, IVsHierarchy hierarchy, Action<MsBuildProject> action) { UnconfiguredProject unconfiguredProject = GetUnconfiguredProject((IVsProject)hierarchy); if (unconfiguredProject != null) { var service = unconfiguredProject.ProjectService.Services.ProjectLockService; if (service != null) { // WriteLockAsync will move us to a background thread. using (ProjectWriteLockReleaser x = await service.WriteLockAsync()) { await x.CheckoutAsync(unconfiguredProject.FullPath); ConfiguredProject configuredProject = await unconfiguredProject.GetSuggestedConfiguredProjectAsync(); MsBuildProject buildProject = await x.GetProjectAsync(configuredProject); if (buildProject != null) { action(buildProject); } await x.ReleaseAsync(); } // perform the save synchronously await Task.Run(() => { // move to the UI thread for the rest of this method unconfiguredProject.ProjectService.Services.ThreadingPolicy.SwitchToUIThread(); var fileSystem = new PhysicalFileSystem(@"c:\"); fileSystem.MakeFileWritable(project.FullName); project.Save(); } ); } } }