public int Execute() { var projectsToMigrate = GetProjectsToMigrate(_projectArg); var msBuildTemplate = _templateFile != null? ProjectRootElement.TryOpen(_templateFile) : _temporaryDotnetNewProject.MSBuildProject; var sdkVersion = _sdkVersion ?? _temporaryDotnetNewProject.MSBuildProject.GetSdkVersion(); EnsureNotNull(sdkVersion, "Null Sdk Version"); MigrationReport migrationReport = null; foreach (var project in projectsToMigrate) { var projectDirectory = Path.GetDirectoryName(project); var outputDirectory = projectDirectory; var migrationSettings = new MigrationSettings(projectDirectory, outputDirectory, sdkVersion, msBuildTemplate, _xprojFilePath); var projectMigrationReport = new ProjectMigrator().Migrate(migrationSettings, _skipProjectReferences); if (migrationReport == null) { migrationReport = projectMigrationReport; } else { migrationReport = migrationReport.Merge(projectMigrationReport); } } WriteReport(migrationReport); return(migrationReport.FailedProjectsCount); }
public async Task CreateInMemoryImport() { if (_unloadCancellationToken.IsCancellationRequested) { return; } using (var access = await _projectLockService.WriteLockAsync(_unloadCancellationToken)) { // A bit odd but we have to "check it out" prior to creating it to avoid some of the validations in chk CPS await access.CheckoutAsync(_inMemoryImportFullPath); // Now either open or create the in-memory file. Normally Create will happen, but in // a scenario where your project had previously failed to load for some reason, need to TryOpen // to avoid a new reason for a project load failure _inMemoryImport = ProjectRootElement.TryOpen(_inMemoryImportFullPath, access.ProjectCollection); if (_inMemoryImport != null) { // The file already exists. Scrape it out so we don’t add duplicate items. _inMemoryImport.RemoveAllChildren(); } else { // The project didn’t already exist, so create it, and then mark the evaluated project dirty // so that MSBuild will notice. This step isn’t necessary if the project was already in memory. _inMemoryImport = CreateEmptyMsBuildProject(_inMemoryImportFullPath, access.ProjectCollection); // Note that we actually need to mark every project evaluation dirty that is already loaded. await ReevaluateLoadedConfiguredProjects(_unloadCancellationToken, access); } _filesItemGroup = _inMemoryImport.AddItemGroup(); _directoriesItemGroup = _inMemoryImport.AddItemGroup(); _temporaryAddedItemGroup = _inMemoryImport.AddItemGroup(); } }
public int Execute() { var projectsToMigrate = GetProjectsToMigrate(_projectArg); var msBuildTemplate = _templateFile != null? ProjectRootElement.TryOpen(_templateFile) : _temporaryDotnetNewProject.MSBuildProject; var sdkVersion = _sdkVersion ?? _temporaryDotnetNewProject.MSBuildProject.GetSdkVersion(); EnsureNotNull(sdkVersion, "Null Sdk Version"); foreach (var project in projectsToMigrate) { Console.WriteLine($"Migrating project {project}.."); var projectDirectory = Path.GetDirectoryName(project); var outputDirectory = projectDirectory; var migrationSettings = new MigrationSettings(projectDirectory, outputDirectory, sdkVersion, msBuildTemplate, _xprojFilePath); new ProjectMigrator().Migrate(migrationSettings, _skipProjectReferences); } return(0); }
public static IEnumerable <CustomCommand> GetCommands( Microsoft.Build.Evaluation.Project project, PythonProjectNode projectNode ) { var commandNames = project.GetPropertyValue(PythonCommands); if (!string.IsNullOrEmpty(commandNames)) { foreach (var name in commandNames.Split(';').Select(s => s.Trim()).Where(n => !string.IsNullOrEmpty(n)).Distinct()) { ProjectTargetInstance targetInstance; if (!project.Targets.TryGetValue(name, out targetInstance)) { continue; } var targetXml = (targetInstance.Location.File == project.FullPath) ? project.Xml : // TryOpen will only return targets that were already // loaded in the current collection; otherwise, null. ProjectRootElement.TryOpen(targetInstance.Location.File, project.ProjectCollection); if (targetXml == null) { continue; } var target = targetXml.Targets.FirstOrDefault(t => name.Equals(t.Name, StringComparison.OrdinalIgnoreCase)); if (target != null) { yield return(new CustomCommand(projectNode, target.Name, target.Label)); } } } }
public int Execute() { var project = GetProjectJsonPath(_projectJson) ?? GetProjectJsonPath(Directory.GetCurrentDirectory()); EnsureNotNull(project, "Unable to find project.json"); var projectDirectory = Path.GetDirectoryName(project); var msBuildTemplate = _templateFile != null? ProjectRootElement.TryOpen(_templateFile) : _temporaryDotnetNewProject.MSBuildProject; var outputDirectory = _outputDirectory ?? projectDirectory; EnsureNotNull(outputDirectory, "Null output directory"); var sdkVersion = _sdkVersion ?? new ProjectJsonParser(_temporaryDotnetNewProject.ProjectJson).SdkPackageVersion; EnsureNotNull(sdkVersion, "Null Sdk Version"); var migrationSettings = new MigrationSettings(projectDirectory, outputDirectory, sdkVersion, msBuildTemplate); new ProjectMigrator().Migrate(migrationSettings); return(0); }
public ORMGeneratorSelectionControl(EnvDTE.ProjectItem projectItem, IServiceProvider serviceProvider) : this() { _projectItem = projectItem; _serviceProvider = serviceProvider; #if VISUALSTUDIO_10_0 ProjectRootElement project = ProjectRootElement.TryOpen(projectItem.ContainingProject.FullName); string projectFullPath = project.FullPath; #else // VISUALSTUDIO_10_0 Project project = Engine.GlobalEngine.GetLoadedProject(projectItem.ContainingProject.FullName); string projectFullPath = project.FullFileName; #endif // VISUALSTUDIO_10_0 _project = project; string projectItemRelativePath = (string)projectItem.Properties.Item("LocalPath").Value; projectItemRelativePath = (new Uri(projectFullPath)).MakeRelativeUri(new Uri(projectItemRelativePath)).ToString(); _projectItemRelativePath = projectItemRelativePath; #if VISUALSTUDIO_10_0 ProjectItemGroupElement originalItemGroup = ORMCustomTool.GetItemGroup(project, projectItemRelativePath); ProjectItemGroupElement itemGroup; if (originalItemGroup == null) { itemGroup = project.AddItemGroup(); itemGroup.Condition = string.Concat(ITEMGROUP_CONDITIONSTART, projectItemRelativePath, ITEMGROUP_CONDITIONEND); } else { itemGroup = project.AddItemGroup(); itemGroup.Condition = originalItemGroup.Condition; foreach (ProjectItemElement item in originalItemGroup.Items) { ProjectItemElement newItem = itemGroup.AddItem(item.ItemType, item.Include); newItem.Condition = item.Condition; foreach (ProjectMetadataElement metadataElement in item.Metadata) { newItem.AddMetadata(metadataElement.Name, metadataElement.Value); } } } #else // VISUALSTUDIO_10_0 BuildItemGroup originalItemGroup = ORMCustomTool.GetItemGroup(project, projectItemRelativePath); BuildItemGroup itemGroup; if (originalItemGroup == null) { itemGroup = project.AddNewItemGroup(); itemGroup.Condition = string.Concat(ITEMGROUP_CONDITIONSTART, projectItemRelativePath, ITEMGROUP_CONDITIONEND); } else { itemGroup = project.AddNewItemGroup(); itemGroup.Condition = originalItemGroup.Condition; foreach (BuildItem item in originalItemGroup) { BuildItem newItem = itemGroup.AddNewItem(item.Name, item.Include, false); newItem.Condition = item.Condition; item.CopyCustomMetadataTo(newItem); } } #endif // VISUALSTUDIO_10_0 _originalItemGroup = originalItemGroup; _itemGroup = itemGroup; string condition = itemGroup.Condition.Trim(); string sourceFileName = this._sourceFileName = projectItem.Name; this.textBox_ORMFileName.Text = sourceFileName; this.button_SaveChanges.Click += new EventHandler(this.SaveChanges); this.button_Cancel.Click += new EventHandler(this.Cancel); ITree tree = (ITree)(this.virtualTreeControl.MultiColumnTree = new MultiColumnTree(2)); this.virtualTreeControl.SetColumnHeaders(new VirtualTreeColumnHeader[] { // TODO: Localize these. new VirtualTreeColumnHeader("Generated File Format", 0.30f, VirtualTreeColumnHeaderStyles.ColumnPositionLocked | VirtualTreeColumnHeaderStyles.DragDisabled), new VirtualTreeColumnHeader("Generated File Name", 1f, VirtualTreeColumnHeaderStyles.ColumnPositionLocked | VirtualTreeColumnHeaderStyles.DragDisabled) }, true); MainBranch mainBranch = this._mainBranch = new MainBranch(this); int totalCount = mainBranch.VisibleItemCount; int[] primaryIndices = new int[totalCount]; for (int i = 0; i < totalCount; ++i) { if (mainBranch.IsPrimaryDisplayItem(i)) { primaryIndices[i] = i - totalCount; } else { primaryIndices[i] = i + 1; } } Array.Sort <int>(primaryIndices); int lastPrimary = -1; for (int i = 0; i < totalCount; ++i) { int modifiedIndex = primaryIndices[i]; if (modifiedIndex < 0) { primaryIndices[i] = modifiedIndex + totalCount; } else { if (lastPrimary == -1) { lastPrimary = i - 1; } primaryIndices[i] = modifiedIndex - 1; } } int modifierCount = totalCount - mainBranch.Branches.Count; tree.Root = (lastPrimary == -1) ? (IBranch)mainBranch : new BranchPartition( mainBranch, primaryIndices, new BranchPartitionSection(0, lastPrimary + 1, null), new BranchPartitionSection(totalCount - modifierCount, modifierCount, "Generated File Modifiers"), new BranchPartitionSection(lastPrimary + 1, totalCount - lastPrimary - modifierCount - 1, "Intermediate and Secondary Files")); // UNDONE: Localize Header this.virtualTreeControl.ShowToolTips = true; this.virtualTreeControl.FullCellSelect = true; #if VISUALSTUDIO_10_0 Dictionary <string, ProjectItemElement> buildItemsByGenerator = this._itemsByGenerator = new Dictionary <string, ProjectItemElement>(itemGroup.Count, StringComparer.OrdinalIgnoreCase); foreach (ProjectItemElement buildItem in itemGroup.Items) #else // VISUALSTUDIO_10_0 Dictionary <string, BuildItem> buildItemsByGenerator = this._itemsByGenerator = new Dictionary <string, BuildItem>(itemGroup.Count, StringComparer.OrdinalIgnoreCase); foreach (BuildItem buildItem in itemGroup) #endif // VISUALSTUDIO_10_0 { // Do this very defensively so that the dialog can still be opened if a project is out // of step with the generators registered on a specific machine. string generatorNameData = buildItem.GetEvaluatedMetadata(ITEMMETADATA_ORMGENERATOR); string[] generatorNames; // The first string is the primary generator, others are the format modifiers int generatorNameCount; IORMGenerator primaryGenerator; MainBranch.OutputFormatBranch primaryFormatBranch; if (!String.IsNullOrEmpty(generatorNameData) && String.Equals(buildItem.GetEvaluatedMetadata(ITEMMETADATA_DEPENDENTUPON), sourceFileName, StringComparison.OrdinalIgnoreCase) && null != (generatorNames = generatorNameData.Split((char[])null, StringSplitOptions.RemoveEmptyEntries)) && 0 != (generatorNameCount = generatorNames.Length) && ORMCustomTool.ORMGenerators.TryGetValue(generatorNames[0], out primaryGenerator) && mainBranch.Branches.TryGetValue(primaryGenerator.ProvidesOutputFormat, out primaryFormatBranch)) { System.Diagnostics.Debug.Assert(primaryFormatBranch.SelectedORMGenerator == null); primaryFormatBranch.SelectedORMGenerator = primaryGenerator; buildItemsByGenerator.Add(generatorNames[0], buildItem); // Format modifiers are attached to the end of the list for (int i = 1; i < generatorNameCount; ++i) { MainBranch.OutputFormatBranch modifierBranch = primaryFormatBranch.NextModifier; string findName = generatorNames[i]; while (modifierBranch != null) { IORMGenerator testGenerator = modifierBranch.ORMGenerators[0]; if (testGenerator.OfficialName == findName) { modifierBranch.SelectedORMGenerator = testGenerator; break; } modifierBranch = modifierBranch.NextModifier; } } } } }
public ORMGeneratorSelectionControl(EnvDTE.ProjectItem projectItem, IServiceProvider serviceProvider) : this() { _projectItem = projectItem; _serviceProvider = serviceProvider; #if VISUALSTUDIO_10_0 ProjectRootElement project = ProjectRootElement.TryOpen(projectItem.ContainingProject.FullName); string projectFullPath = project.FullPath; #else // VISUALSTUDIO_10_0 Microsoft.Build.BuildEngine.Project project = Engine.GlobalEngine.GetLoadedProject(projectItem.ContainingProject.FullName); string projectFullPath = project.FullFileName; #endif // VISUALSTUDIO_10_0 _project = project; string projectItemRelativePath = (string)projectItem.Properties.Item("LocalPath").Value; projectItemRelativePath = (new Uri(projectFullPath)).MakeRelativeUri(new Uri(projectItemRelativePath)).ToString(); _projectItemRelativePath = projectItemRelativePath; #if VISUALSTUDIO_10_0 ProjectItemGroupElement originalItemGroup = ORMCustomTool.GetItemGroup(project, projectItemRelativePath); #else // VISUALSTUDIO_10_0 BuildItemGroup originalItemGroup = ORMCustomTool.GetItemGroup(project, projectItemRelativePath); #endif // VISUALSTUDIO_10_0 _originalItemGroup = originalItemGroup; string sourceFileName = projectItem.Name; _sourceFileName = sourceFileName; this.textBox_ORMFileName.Text = sourceFileName; this.button_SaveChanges.Click += new EventHandler(this.SaveChanges); this.button_Cancel.Click += new EventHandler(this.Cancel); ITree tree = (ITree)(this.virtualTreeControl.MultiColumnTree = new MultiColumnTree(2)); this.virtualTreeControl.SetColumnHeaders(new VirtualTreeColumnHeader[] { // TODO: Localize these. new VirtualTreeColumnHeader("Generated File Format", 0.30f, VirtualTreeColumnHeaderStyles.ColumnPositionLocked | VirtualTreeColumnHeaderStyles.DragDisabled), new VirtualTreeColumnHeader("Generated File Name", 1f, VirtualTreeColumnHeaderStyles.ColumnPositionLocked | VirtualTreeColumnHeaderStyles.DragDisabled) }, true); MainBranch mainBranch = this._mainBranch = new MainBranch(this #if VISUALSTUDIO_15_0 , serviceProvider #endif ); int totalCount = mainBranch.VisibleItemCount; int[] primaryIndices = new int[totalCount]; for (int i = 0; i < totalCount; ++i) { if (mainBranch.IsPrimaryDisplayItem(i)) { primaryIndices[i] = i - totalCount; } else { primaryIndices[i] = i + 1; } } Array.Sort <int>(primaryIndices); int lastPrimary = -1; for (int i = 0; i < totalCount; ++i) { int modifiedIndex = primaryIndices[i]; if (modifiedIndex < 0) { primaryIndices[i] = modifiedIndex + totalCount; } else { if (lastPrimary == -1) { lastPrimary = i - 1; } primaryIndices[i] = modifiedIndex - 1; } } int modifierCount = totalCount - mainBranch.Branches.Count; tree.Root = (lastPrimary == -1) ? (IBranch)mainBranch : new BranchPartition( mainBranch, primaryIndices, new BranchPartitionSection(0, lastPrimary + 1), new BranchPartitionSection(totalCount - modifierCount, modifierCount, "Generated File Modifiers", false), new BranchPartitionSection(lastPrimary + 1, totalCount - lastPrimary - modifierCount - 1, "Intermediate and Secondary Files", true)); // UNDONE: Localize Header this.virtualTreeControl.ShowToolTips = true; this.virtualTreeControl.FullCellSelect = true; Dictionary <string, PseudoBuildItem> pseudoItemsByOutputFormat = new Dictionary <string, PseudoBuildItem>(StringComparer.OrdinalIgnoreCase); _pseudoItemsByOutputFormat = pseudoItemsByOutputFormat; IDictionary <string, IORMGenerator> generators = #if VISUALSTUDIO_15_0 ORMCustomTool.GetORMGenerators(serviceProvider); #else ORMCustomTool.ORMGenerators; #endif if (originalItemGroup != null) { #if VISUALSTUDIO_10_0 foreach (ProjectItemElement buildItem in originalItemGroup.Items) #else // VISUALSTUDIO_10_0 foreach (BuildItem buildItem in originalItemGroup) #endif // VISUALSTUDIO_10_0 { // Do this very defensively so that the dialog can still be opened if a project is out // of step with the generators registered on a specific machine. string generatorNameData; string[] generatorNames; // The first string is the primary generator, others are the format modifiers int generatorNameCount; IORMGenerator primaryGenerator; MainBranch.OutputFormatBranch primaryFormatBranch; if (!string.IsNullOrEmpty(generatorNameData = buildItem.GetEvaluatedMetadata(ITEMMETADATA_ORMGENERATOR)) && !string.IsNullOrEmpty(generatorNameData = generatorNameData.Trim()) && string.Equals(buildItem.GetEvaluatedMetadata(ITEMMETADATA_DEPENDENTUPON), sourceFileName, StringComparison.OrdinalIgnoreCase) && null != (generatorNames = generatorNameData.Split((char[])null, StringSplitOptions.RemoveEmptyEntries)) && 0 != (generatorNameCount = generatorNames.Length) && // This assumes that each generator target of the same type has all of the same options. // This is currently the result of this dialog, and we're not considering hand edits // to the project file at this point. generators.TryGetValue(generatorNames[0], out primaryGenerator) && mainBranch.Branches.TryGetValue(primaryGenerator.ProvidesOutputFormat, out primaryFormatBranch)) { PseudoBuildItem pseudoItem; string outputFormat = primaryGenerator.ProvidesOutputFormat; if (!pseudoItemsByOutputFormat.TryGetValue(outputFormat, out pseudoItem)) { // Note that we can't use the build item file name here as it might be decorated with // target names. Go back to the generator to get an undecorated default name. pseudoItem = new PseudoBuildItem(generatorNameData, primaryGenerator.GetOutputFileDefaultName(sourceFileName)); pseudoItemsByOutputFormat.Add(outputFormat, pseudoItem); if (primaryFormatBranch.SelectedORMGenerator == null) { primaryFormatBranch.SelectedORMGenerator = primaryGenerator; } // Format modifiers are attached to the end of the list for (int i = 1; i < generatorNameCount; ++i) { MainBranch.OutputFormatBranch modifierBranch = primaryFormatBranch.NextModifier; string findName = generatorNames[i]; while (modifierBranch != null) { IORMGenerator testGenerator = modifierBranch.ORMGenerators[0]; if (testGenerator.OfficialName == findName) { modifierBranch.SelectedORMGenerator = testGenerator; break; } modifierBranch = modifierBranch.NextModifier; } } } pseudoItem.AddOriginalInstance(generatorNameData, ORMCustomToolUtility.GeneratorTargetsFromBuildItem(buildItem)); } } } }