public async Task <ImmutableArray <ProjectFileInfo> > GetProjectFileInfosAsync(CancellationToken cancellationToken) { var targetFrameworkValue = _loadedProject.GetPropertyValue(PropertyNames.TargetFramework); var targetFrameworksValue = _loadedProject.GetPropertyValue(PropertyNames.TargetFrameworks); if (string.IsNullOrEmpty(targetFrameworkValue) && !string.IsNullOrEmpty(targetFrameworksValue)) { // This project has a <TargetFrameworks> property, but does not specify a <TargetFramework>. // In this case, we need to iterate through the <TargetFrameworks>, set <TargetFramework> with // each value, and build the project. var hasTargetFrameworkProp = _loadedProject.GetProperty(PropertyNames.TargetFramework) != null; var targetFrameworks = targetFrameworksValue.Split(';'); var results = ImmutableArray.CreateBuilder <ProjectFileInfo>(targetFrameworks.Length); foreach (var targetFramework in targetFrameworks) { _loadedProject.SetProperty(PropertyNames.TargetFramework, targetFramework); _loadedProject.ReevaluateIfNecessary(); var projectFileInfo = await BuildProjectFileInfoAsync(cancellationToken).ConfigureAwait(false); results.Add(projectFileInfo); } // Remove the <TargetFramework> property if it didn't exist in the file before we set it. // Otherwise, set it back to it's original value. if (!hasTargetFrameworkProp) { var targetFrameworkProp = _loadedProject.GetProperty(PropertyNames.TargetFramework); _loadedProject.RemoveProperty(targetFrameworkProp); } else { _loadedProject.SetProperty(PropertyNames.TargetFramework, targetFrameworkValue); } _loadedProject.ReevaluateIfNecessary(); return(results.ToImmutable()); } else { var projectFileInfo = await BuildProjectFileInfoAsync(cancellationToken).ConfigureAwait(false); return(ImmutableArray.Create(projectFileInfo)); } }
public string GetDefNamespace() { Microsoft.Build.Evaluation.Project pc = null; try { pc = new Microsoft.Build.Evaluation.Project(FileName); } catch (Exception e) { } if (pc == null) { return(""); } Microsoft.Build.Evaluation.ProjectProperty assname = pc.GetProperty("RootNamespace"); string s = assname.EvaluatedValue; pc.ProjectCollection.UnloadAllProjects(); return(s); }
public string SetProperties(string file) { Microsoft.Build.Evaluation.Project pc = new Microsoft.Build.Evaluation.Project(file); if (pc == null) { return(""); } Microsoft.Build.Evaluation.ProjectProperty outtype = pc.GetProperty("OutputType"); Microsoft.Build.Evaluation.ProjectProperty outdir = pc.GetProperty("OutDir"); Microsoft.Build.Evaluation.ProjectProperty assname = pc.GetProperty("AssemblyName"); string s = outdir.EvaluatedValue + "\\" + assname.EvaluatedValue; pc.ProjectCollection.UnloadAllProjects(); return(s); }
public string GetOutDirs() { Microsoft.Build.Evaluation.Project pc = null; try { pc = new Microsoft.Build.Evaluation.Project(FileName); } catch (Exception e) { } if (pc == null) { return(""); } Microsoft.Build.Evaluation.ProjectProperty outtype = pc.GetProperty("OutputType"); Microsoft.Build.Evaluation.ProjectProperty outdir = pc.GetProperty("OutDir"); Microsoft.Build.Evaluation.ProjectProperty assname = pc.GetProperty("AssemblyName"); string ext = ".dll"; if (outtype.EvaluatedValue == "WinExe") { ext = ".exe"; } string s = Path.GetDirectoryName(FileName) + "\\" + outdir.EvaluatedValue; pc.ProjectCollection.UnloadAllProjects(); return(s); }
private static void UpdateProjectFile(string projectFilePath, int?newValue) { var project = new Microsoft.Build.Evaluation.Project(projectFilePath); var property = project.GetProperty("ApplicationRevision"); if (newValue.HasValue) { property.UnevaluatedValue = newValue.Value.ToString(); } else { property.UnevaluatedValue = (System.Int32.Parse(property.EvaluatedValue) + 1).ToString(); } project.Save(); }
public MSB.Evaluation.ProjectProperty GetProperty(string name) { return(_loadedProject.GetProperty(name)); }
public static bool UpgradeProjectProperties(Microsoft.Build.Evaluation.Project project, bool cpp) { bool modified = false; string outputDir = null; string headerOutputDir = null; string baseDirectoryForGeneratedInclude = null; string value = project.GetProperty(PropertyNames.Old.OutputDir, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.OutputDir); value = value.Replace("$(IceBuilder", "%("); project.SetItemMetadata(ItemMetadataNames.OutputDir, value); modified = true; outputDir = value; } else if (cpp) { // The default output directory for C++ generated items was changed to $(IntDir) // but we keep the old default when converted projects by setting it in the project // file project.SetItemMetadata(ItemMetadataNames.OutputDir, "generated"); outputDir = "generated"; } value = project.GetProperty(PropertyNames.Old.IncludeDirectories, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.IncludeDirectories); value = value.Replace("$(IceHome)\\slice", ""); value = value.Replace("$(IceHome)/slice", ""); value = value.Trim(';'); value = value.Replace("$(IceBuilder", "%("); if (!string.IsNullOrEmpty(value)) { project.SetItemMetadata(ItemMetadataNames.IncludeDirectories, value); } modified = true; } value = project.GetProperty(PropertyNames.Old.HeaderOutputDir, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.HeaderOutputDir); value = value.Replace("$(IceBuilder", "%("); project.SetItemMetadata(ItemMetadataNames.HeaderOutputDir, value); modified = true; headerOutputDir = value; } value = project.GetProperty(PropertyNames.Old.HeaderExt, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.HeaderExt); project.SetItemMetadata(ItemMetadataNames.HeaderExt, value); modified = true; } value = project.GetProperty(PropertyNames.Old.BaseDirectoryForGeneratedInclude, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.BaseDirectoryForGeneratedInclude); project.SetItemMetadata(ItemMetadataNames.BaseDirectoryForGeneratedInclude, value); modified = true; baseDirectoryForGeneratedInclude = value; } value = project.GetProperty(PropertyNames.Old.SourceExt, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.SourceExt); project.SetItemMetadata(ItemMetadataNames.SourceExt, value); modified = true; } value = project.GetProperty(PropertyNames.Old.AllowIcePrefix, false); string additionalOptions = project.GetProperty(PropertyNames.Old.AdditionalOptions, false); if (!string.IsNullOrEmpty(additionalOptions)) { project.RemovePropertyWithName(PropertyNames.Old.AdditionalOptions); modified = true; } if (!string.IsNullOrEmpty(value)) { if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase) || value.Equals("true", StringComparison.CurrentCultureIgnoreCase)) { additionalOptions = String.Format("{0} --ice", additionalOptions).Trim(); } project.RemovePropertyWithName(PropertyNames.Old.AllowIcePrefix); modified = true; } value = project.GetProperty(PropertyNames.Old.Underscore, false); if (!string.IsNullOrEmpty(value)) { if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase) || value.Equals("true", StringComparison.CurrentCultureIgnoreCase)) { additionalOptions = String.Format("{0} --underscore", additionalOptions).Trim(); } project.RemovePropertyWithName(PropertyNames.Old.Underscore); modified = true; } value = project.GetProperty(PropertyNames.Old.Stream, false); if (!string.IsNullOrEmpty(value)) { if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase) || value.Equals("true", StringComparison.CurrentCultureIgnoreCase)) { additionalOptions = String.Format("{0} --stream ", additionalOptions).Trim(); } project.RemovePropertyWithName(PropertyNames.Old.Stream); modified = true; } value = project.GetProperty(PropertyNames.Old.DLLExport, false); if (!string.IsNullOrEmpty(value)) { additionalOptions = String.Format("{0} --dll-export {1}", additionalOptions, value).Trim(); project.RemovePropertyWithName(PropertyNames.Old.DLLExport); modified = true; } value = project.GetProperty(PropertyNames.Old.Checksum, false); if (!string.IsNullOrEmpty(value)) { additionalOptions = String.Format("{0} --checksum", additionalOptions).Trim(); project.RemovePropertyWithName(PropertyNames.Old.Checksum); modified = true; } value = project.GetProperty(PropertyNames.Old.Tie, false); if (!string.IsNullOrEmpty(value)) { additionalOptions = String.Format("{0} --tie", additionalOptions).Trim(); project.RemovePropertyWithName(PropertyNames.Old.Tie); modified = true; } if (!string.IsNullOrEmpty(additionalOptions)) { additionalOptions = additionalOptions.Replace("IceBuilder", "SliceCompile"); project.SetItemMetadata(ItemMetadataNames.AdditionalOptions, additionalOptions); } if (string.IsNullOrEmpty(baseDirectoryForGeneratedInclude)) { if (!string.IsNullOrEmpty(headerOutputDir)) { project.SetClCompileAdditionalIncludeDirectories(headerOutputDir); } else { project.SetClCompileAdditionalIncludeDirectories(outputDir); } } value = project.GetProperty("ProjectTypeGuids", false); if (!string.IsNullOrEmpty(value)) { value = value.Replace(Package.IceBuilderOldFlavor, Package.IceBuilderNewFlavor); project.SetProperty("ProjectTypeGuids", value, ""); modified = true; } return(modified); }