public static IProjectStore CreateInstance(Microsoft.Expression.Framework.Documents.DocumentReference documentReference, IServiceProvider serviceProvider) { if (documentReference == null) { throw new ArgumentNullException("documentReference"); } if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } if (!documentReference.IsValidPathFormat) { throw new ArgumentException("Document reference must be a valid path.", "documentReference"); } if (!File.Exists(documentReference.Path)) { throw new FileNotFoundException("File not found.", documentReference.Path); } string safeExtension = Microsoft.Expression.Framework.Documents.PathHelper.GetSafeExtension(documentReference.Path); if (string.IsNullOrEmpty(safeExtension)) { return(null); } if (!MSBuildBasedProjectStore.KnownMSBuildExtensions.Contains <string>(safeExtension.ToUpperInvariant())) { return(null); } MSBuildBasedProjectStore mSBuildBasedProjectStore = new MSBuildBasedProjectStore(documentReference); mSBuildBasedProjectStore.LoadProject(); mSBuildBasedProjectStore.blendVersion = (serviceProvider.ExpressionInformationService() == null ? "0.0.0.0" : serviceProvider.ExpressionInformationService().Version.ToString()); return(mSBuildBasedProjectStore); }
private MigratingMSBuildStore(Microsoft.Expression.Framework.Documents.DocumentReference documentReference, IServiceProvider serviceProvider) { this.DocumentReference = documentReference; this.serviceProvider = serviceProvider; this.AttemptToMigrate = (bool callerSuccess) => { if (!callerSuccess) { return(callerSuccess); } try { ProjectPathHelper.AttemptToMakeWritable(this.DocumentReference, this.serviceProvider); this.Save(); IProjectStore projectStore = MSBuildBasedProjectStore.CreateInstance(this.DocumentReference, this.serviceProvider); this.NestedStore.Dispose(); this.NestedStore = projectStore; this.AttemptToMigrate = (bool value) => value; } catch (InvalidProjectFileException invalidProjectFileException) { this.LastError = invalidProjectFileException; } return(callerSuccess); }; }
public static IProjectStore CreateInstance(Microsoft.Expression.Framework.Documents.DocumentReference documentReference, IServiceProvider serviceProvider) { IProjectStore projectStore; try { projectStore = MSBuildBasedProjectStore.CreateInstance(documentReference, serviceProvider); } catch (InvalidProjectFileException invalidProjectFileException1) { InvalidProjectFileException invalidProjectFileException = invalidProjectFileException1; MigratingMSBuildStore migratingMSBuildStore = new MigratingMSBuildStore(documentReference, serviceProvider) { LastError = invalidProjectFileException, NestedStore = XmlMSBuildProjectStore.CreateInstance(documentReference, serviceProvider) }; projectStore = migratingMSBuildStore; } return(projectStore); }
internal static void RepairAssemblyReferences(IProjectStore projectStore) { MSBuildBasedProjectStore mSBuildBasedProjectStore = projectStore as MSBuildBasedProjectStore; if (mSBuildBasedProjectStore == null) { return; } ProjectBuildContext projectBuildContext = mSBuildBasedProjectStore.GenerateNewBuildContext(null); AssemblyReferenceHelper.RebuildAssemblyReferencePaths(projectBuildContext); foreach (ItemResolutionPair itemResolutionPair in from assemblyPath in AssemblyReferenceHelper.GetAssemblyPaths(projectStore, projectBuildContext) where assemblyPath.ResolvedItem == null select assemblyPath) { string value = itemResolutionPair.SourceItem.Value; if (string.IsNullOrEmpty(value)) { continue; } int num = value.IndexOf(','); string fileNameWithoutExtension = null; if (num <= 0) { try { fileNameWithoutExtension = Path.GetFileNameWithoutExtension(value); } catch (IOException oException) { continue; } catch (ArgumentException argumentException) { continue; } if (string.Equals(fileNameWithoutExtension, value, StringComparison.OrdinalIgnoreCase)) { continue; } } else { fileNameWithoutExtension = value.Substring(0, num); } itemResolutionPair.SourceItem.Value = fileNameWithoutExtension; itemResolutionPair.SourceItem.SetItemMetadata("UpgraderOriginalValue", value); } projectBuildContext = mSBuildBasedProjectStore.GenerateNewBuildContext(null); AssemblyReferenceHelper.RebuildAssemblyReferencePaths(projectBuildContext); foreach (ItemResolutionPair itemResolutionPair1 in AssemblyReferenceHelper.GetAssemblyPaths(projectStore, projectBuildContext)) { string metadata = itemResolutionPair1.SourceItem.GetMetadata("UpgraderOriginalValue"); if (string.IsNullOrEmpty(metadata)) { continue; } if (itemResolutionPair1.ResolvedItem != null) { string path = projectStore.DocumentReference.Path; string updateItemMetadataAction = StringTable.UpdateItemMetadataAction; object[] itemType = new object[] { "Include", itemResolutionPair1.SourceItem.ItemType, metadata, metadata, itemResolutionPair1.SourceItem.Value }; ProjectLog.LogSuccess(path, updateItemMetadataAction, itemType); string metadataValue = itemResolutionPair1.ResolvedItem.GetMetadataValue("RequiredTargetFramework"); if (!string.IsNullOrEmpty(metadataValue)) { itemResolutionPair1.SourceItem.SetItemMetadata("RequiredTargetFramework", metadataValue); } } else { itemResolutionPair1.SourceItem.Value = metadata; } itemResolutionPair1.SourceItem.SetItemMetadata("UpgraderOriginalValue", null); } }