public ProjectEditor() { Project = new MSBuildProject(); var pg = Project.AddNewPropertyGroup(true); Project.ToolsVersion = "4.0"; Project.DefaultTargets = "Build"; pg["SchemaVersion"] = "2.0"; pg["ProjectGuid"] = ProjectTypeGuids.CSharp; OutputType = CSharpProjectOutputTypes.Library.ToString(); ProductVersion = "10.0.0"; AssemblyName = "Untitled"; RootNameSpace = "Untitled"; pg ["Configuration"] = "Debug"; pg ["Platform"] = "AnyCPU"; AddReleaseConfig(false, "AnyCPU", "bin\\Release"); AddDebugConfig(true, "AnyCPU", "bin\\Debug"); Project.AddNewImport("$(MSBuildBinPath)\\Microsoft.CSharp.targets", null); ProjectFolder = Environment.CurrentDirectory; }
private static CsProjFile CreateCore(MSBuildProject project, string fileName) { var group = project.PropertyGroups.FirstOrDefault(x => x.Properties.Any(p => p.Name == PROJECTGUID)) ?? project.PropertyGroups.FirstOrDefault() ?? project.AddNewPropertyGroup(true); @group.SetPropertyValue(PROJECTGUID, Guid.NewGuid().ToString().ToUpper(), true); var file = new CsProjFile(fileName, project); file.AssemblyName = file.RootNamespace = file.ProjectName; return(file); }
protected override void OnWriteProject(ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) { if (projItemsPath == FilePath.Null) { projItemsPath = Path.ChangeExtension(FileName, ".projitems"); } if (projitemsProject == null) { projitemsProject = new MSBuildProject(msproject.EngineManager); projitemsProject.FileName = projItemsPath; var grp = projitemsProject.GetGlobalPropertyGroup(); if (grp == null) { grp = projitemsProject.AddNewPropertyGroup(false); } grp.SetValue("MSBuildAllProjects", "$(MSBuildAllProjects);$(MSBuildThisFileFullPath)"); grp.SetValue("HasSharedItems", true); grp.SetValue("SharedGUID", ItemId, preserveExistingCase: true); } IMSBuildPropertySet configGrp = projitemsProject.PropertyGroups.FirstOrDefault(g => g.Label == "Configuration"); if (configGrp == null) { configGrp = projitemsProject.AddNewPropertyGroup(true); configGrp.Label = "Configuration"; } configGrp.SetValue("Import_RootNamespace", DefaultNamespace); base.OnWriteProject(monitor, msproject); var newProject = FileName == null || !File.Exists(FileName); if (newProject) { var grp = msproject.GetGlobalPropertyGroup(); if (grp == null) { grp = msproject.AddNewPropertyGroup(false); } grp.SetValue("ProjectGuid", ItemId, preserveExistingCase: true); var import = msproject.AddNewImport(@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"); import.Condition = @"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"; msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props"); msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props"); import = msproject.AddNewImport(Path.ChangeExtension(FileName.FileName, ".projitems")); import.Label = "Shared"; if (LanguageName.Equals("C#", StringComparison.OrdinalIgnoreCase)) { msproject.AddNewImport(CSharptargets); } else if (LanguageName.Equals("F#", StringComparison.OrdinalIgnoreCase)) { msproject.AddNewImport(FSharptargets); } } else { msproject.Load(FileName); } // having no ToolsVersion is equivalent to 2.0, roundtrip that correctly if (ToolsVersion != "2.0") { msproject.ToolsVersion = ToolsVersion; } else if (string.IsNullOrEmpty(msproject.ToolsVersion)) { msproject.ToolsVersion = null; } else { msproject.ToolsVersion = "2.0"; } projitemsProject.Save(projItemsPath); }
public void SetPropertyValue(string key, string value) { var msBuildPropertyGroup = _project.AddNewPropertyGroup(false); msBuildPropertyGroup.SetPropertyValue(key, value, false); }
protected override MSBuildProject SaveProject(IProgressMonitor monitor) { MSBuildSerializer ser = CreateSerializer(); ser.SerializationContext.BaseFile = EntityItem.FileName; ser.SerializationContext.ProgressMonitor = monitor; MSBuildProject projitemsProject = new MSBuildProject(); MSBuildProject msproject = new MSBuildProject(); var newProject = EntityItem.FileName == null || !File.Exists(EntityItem.FileName); if (newProject) { var grp = msproject.GetGlobalPropertyGroup(); if (grp == null) { grp = msproject.AddNewPropertyGroup(false); } grp.SetPropertyValue("ProjectGuid", EntityItem.ItemId, false); var import = msproject.AddNewImport(@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"); import.Condition = @"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"; msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props"); msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props"); import = msproject.AddNewImport(Path.ChangeExtension(EntityItem.FileName.FileName, ".projitems")); import.Label = "Shared"; msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets"); } else { msproject.Load(EntityItem.FileName); } // having no ToolsVersion is equivalent to 2.0, roundtrip that correctly if (ToolsVersion != "2.0") { msproject.ToolsVersion = ToolsVersion; } else if (string.IsNullOrEmpty(msproject.ToolsVersion)) { msproject.ToolsVersion = null; } else { msproject.ToolsVersion = "2.0"; } if (projitemsFile == null) { projitemsFile = ((SharedAssetsProject)Item).ProjItemsPath; } if (File.Exists(projitemsFile)) { projitemsProject.Load(projitemsFile); } else { var grp = projitemsProject.AddNewPropertyGroup(true); grp.SetPropertyValue("MSBuildAllProjects", "$(MSBuildAllProjects);$(MSBuildThisFileFullPath)", false); grp.SetPropertyValue("HasSharedItems", "true", false); grp.SetPropertyValue("SharedGUID", EntityItem.ItemId, false); } var configGrp = projitemsProject.PropertyGroups.FirstOrDefault(g => g.Label == "Configuration"); if (configGrp == null) { configGrp = projitemsProject.AddNewPropertyGroup(true); configGrp.Label = "Configuration"; } configGrp.SetPropertyValue("Import_RootNamespace", ((SharedAssetsProject)EntityItem).DefaultNamespace, false); SaveProjectItems(monitor, new MSBuildFileFormatVS12(), ser, projitemsProject, "$(MSBuildThisFileDirectory)"); projitemsProject.Save(projitemsFile); return(msproject); }
MSBuildPropertyGroup AddPropertyGroup() { return(msbuildProject.AddNewPropertyGroup(true)); }
private static CsProjFile CreateCore(MSBuildProject project, string fileName) { MSBuildPropertyGroup arg_42_0; if ((arg_42_0 = project.PropertyGroups.FirstOrDefault((MSBuildPropertyGroup x) => x.Properties.Any((MSBuildProperty p) => p.Name == "ProjectGuid"))) == null) { arg_42_0 = (project.PropertyGroups.FirstOrDefault <MSBuildPropertyGroup>() ?? project.AddNewPropertyGroup(true)); } MSBuildPropertyGroup group = arg_42_0; group.SetPropertyValue("ProjectGuid", Guid.NewGuid().ToString().ToUpper(), true); CsProjFile file = new CsProjFile(fileName, project); file.AssemblyName = (file.RootNamespace = file.ProjectName); return(file); }