IList <SdkResolver> LoadResolvers(ILoggingService logger) { // Add the MonoDevelop resolver, which resolves SDKs registered by add-ins. // Also add the default resolver. var resolvers = new List <SdkResolver> { new MonoDevelop.Projects.MSBuild.Resolver(MSBuildProjectService.FindRegisteredSdks), new DefaultSdkResolver { TargetRuntime = runtime } }; MSBuildProjectService.GetNewestInstalledToolsVersion(runtime, true, out var binDir); var potentialResolvers = FindPotentialSdkResolvers(Path.Combine(binDir, "SdkResolvers")); if (potentialResolvers.Count == 0) { return(resolvers); } foreach (var potentialResolver in potentialResolvers) { try { var assembly = Assembly.LoadFrom(potentialResolver); resolvers.AddRange(assembly.ExportedTypes .Select(type => new { type, info = type.GetTypeInfo() }) .Where(t => t.info.IsClass && t.info.IsPublic && typeof(SdkResolver).IsAssignableFrom(t.type)) .Select(t => (SdkResolver)Activator.CreateInstance(t.type))); } catch (Exception e) { logger.LogWarning(e.Message); } } return(resolvers.OrderBy(t => t.Priority).ToList()); }
object ConvertArg(MethodBase method, int argNum, object value, Type parameterType) { var sval = value as string; if (sval == "null" || value == null) { return(null); } if (sval != null && parameterType == typeof(char[])) { return(sval.ToCharArray()); } if (sval != null && parameterType.IsEnum) { var enumValue = sval; if (enumValue.StartsWith(parameterType.Name)) { enumValue = enumValue.Substring(parameterType.Name.Length + 1); } if (enumValue.StartsWith(parameterType.FullName)) { enumValue = enumValue.Substring(parameterType.FullName.Length + 1); } return(Enum.Parse(parameterType, enumValue, ignoreCase: true)); } if (sval != null && Path.DirectorySeparatorChar != '\\') { value = sval.Replace('\\', Path.DirectorySeparatorChar); } var res = Convert.ChangeType(value, parameterType, CultureInfo.InvariantCulture); bool convertPath = false; if ((method.DeclaringType == typeof(System.IO.File) || method.DeclaringType == typeof(System.IO.Directory)) && argNum == 0) { convertPath = true; } else if (method.DeclaringType == typeof(IntrinsicFunctions)) { if (method.Name == "MakeRelative") { convertPath = true; } else if (method.Name == "GetDirectoryNameOfFileAbove" && argNum == 0) { convertPath = true; } } // The argument is a path. Convert to native path and make absolute if (convertPath) { res = MSBuildProjectService.FromMSBuildPath(project.BaseDirectory, (string)res); } return(res); }
IList <SdkResolver> LoadResolvers(ILoggingService logger) { // Add the MonoDevelop resolver, which resolves SDKs registered by add-ins. // Also add the default resolver. var resolvers = new List <SdkResolver> { new MonoDevelop.Projects.MSBuild.Resolver(MSBuildProjectService.FindRegisteredSdks), new DefaultSdkResolver { TargetRuntime = runtime } }; var binDir = MSBuildProjectService.GetMSBuildBinPath(runtime); var potentialResolvers = FindPotentialSdkResolvers(Path.Combine(binDir, "SdkResolvers"), logger); if (potentialResolvers.Count == 0) { return(resolvers); } foreach (var potentialResolver in potentialResolvers) { LoadResolvers(potentialResolver, logger, resolvers); } return(resolvers.OrderBy(t => t.Priority).ToList()); }
public async Task AddFileToDotNetCoreProjectWithDefaultItemsDisabled() { FilePath solFile = Util.GetSampleProject("dotnetcore-console", "dotnetcore-disable-default-items.sln"); FilePath sdksPath = solFile.ParentDirectory.Combine("Sdks"); MSBuildProjectService.RegisterProjectImportSearchPath("MSBuildSDKsPath", sdksPath); try { var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); var p = (Project)sol.Items [0]; Assert.IsInstanceOf <Project> (p); var mp = (Project)p; var files = mp.Files.Select(f => f.FilePath.FileName).ToArray(); Assert.AreEqual(new string [] { "Program.cs" }, files); string newFile = mp.Files [0].FilePath.ChangeName("NewFile"); File.WriteAllText(newFile, string.Empty); mp.AddFile(newFile); await mp.SaveAsync(Util.GetMonitor()); var itemGroup = mp.MSBuildProject.ItemGroups.LastOrDefault(); Assert.IsTrue(itemGroup.Items.Any(item => item.Include == "NewFile.cs")); Assert.AreEqual(2, itemGroup.Items.Count()); sol.Dispose(); } finally { MSBuildProjectService.UnregisterProjectImportSearchPath("MSBuildSDKsPath", sdksPath); } }
public static async Task CheckGenericItemProject(MSBuildFileFormat format) { Solution sol = new Solution(); sol.ConvertToFormat(format); string dir = Util.CreateTmpDir("generic-item"); sol.FileName = Path.Combine(dir, "TestGenericItem"); sol.Name = "TheItem"; MSBuildProjectService.RegisterGenericProjectType("GenericItem", typeof(GenericItem)); GenericItem it = new GenericItem(); it.SomeValue = "hi"; sol.RootFolder.Items.Add(it); it.FileName = Path.Combine(dir, "TheItem"); it.Name = "TheItem"; await sol.SaveAsync(Util.GetMonitor()); Solution sol2 = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), sol.FileName); Assert.AreEqual(1, sol2.Items.Count); Assert.IsInstanceOf <GenericItem> (sol2.Items [0]); it = (GenericItem)sol2.Items [0]; Assert.AreEqual("hi", it.SomeValue); sol.Dispose(); }
public bool TryGetPathValue(string name, out FilePath value, FilePath defaultValue = default(FilePath), bool relativeToSolution = true, FilePath relativeToPath = default(FilePath)) { string val; if (TryGetValue(name, out val)) { string baseDir = null; if (relativeToPath != null) { baseDir = relativeToPath; } else if (relativeToSolution && ParentFile != null && ParentFile.FileName != null) { baseDir = ParentFile.FileName.ParentDirectory; } string path; var res = MSBuildProjectService.FromMSBuildPath(baseDir, val, out path); value = path; return(res); } else { value = defaultValue; return(value != default(FilePath)); } }
public async Task UpdatePackage_ReferenceHasFullyQualifiedPath_ReferenceHasFullyQualifiedPathAfterUpdate() { FilePath solutionFileName = Util.GetSampleProject("ReferenceFullPath", "ReferenceFullPath.sln"); FilePath projectFileName = solutionFileName.ParentDirectory.Combine("ReferenceFullPath.csproj"); FilePath packagesDirectory = solutionFileName.ParentDirectory.Combine("packages"); string projectXml = File.ReadAllText(projectFileName); string solutionDirectory = MSBuildProjectService.ToMSBuildPath(null, solutionFileName.ParentDirectory); string updatedProjectXml = projectXml.Replace("$(SolutionDir)", solutionDirectory); File.WriteAllText(projectFileName, updatedProjectXml); using (solution = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solutionFileName)) { CreateNuGetConfigFile(solution.BaseDirectory); var project = (DotNetProject)solution.FindProjectByName("ReferenceFullPath"); var restoreResult = await RestoreNuGetPackages(solution); Assert.IsTrue(restoreResult.Restored); Assert.AreEqual(1, restoreResult.RestoredPackages.Count()); // Update NuGet package await UpdateNuGetPackage(project, "Test.Xam.NetStandard"); string expectedXml = Util.ToSystemEndings(File.ReadAllText(project.FileName.ChangeExtension(".csproj-saved"))); expectedXml = expectedXml.Replace("$(SolutionDir)", solutionDirectory); string actualXml = File.ReadAllText(project.FileName); Assert.AreEqual(expectedXml, actualXml); } }
string[] GetImportFiles(ProjectInfo project, MSBuildEvaluationContext context, MSBuildImport import, string extensionsPath) { var tempCtx = new MSBuildEvaluationContext(context); var mep = MSBuildProjectService.ToMSBuildPath(null, extensionsPath); tempCtx.SetPropertyValue("MSBuildExtensionsPath", mep); tempCtx.SetPropertyValue("MSBuildExtensionsPath32", mep); tempCtx.SetPropertyValue("MSBuildExtensionsPath64", mep); var pr = context.EvaluateString(import.Project); project.Imports [import] = pr; if (!string.IsNullOrEmpty(import.Condition) && !SafeParseAndEvaluate(project, tempCtx, import.Condition, true)) { return(null); } var path = MSBuildProjectService.FromMSBuildPath(project.Project.BaseDirectory, pr); var fileName = Path.GetFileName(path); if (fileName.IndexOfAny(new [] { '*', '?' }) == -1) { return(File.Exists(path) ? new [] { path } : null); } else { var files = Directory.GetFiles(Path.GetDirectoryName(path), fileName); Array.Sort(files); return(files); } }
public bool TryGetPathValue(out FilePath value, bool relativeToProject = true, FilePath relativeToPath = default(FilePath)) { var val = GetPropertyValue(); string baseDir = null; if (relativeToPath != null) { baseDir = relativeToPath; } else if (relativeToProject) { if (ParentProject == null) { // The path can't yet be resolved, return the raw value value = val; return(true); } baseDir = ParentProject.BaseDirectory; } string path; var res = MSBuildProjectService.FromMSBuildPath(baseDir, val, out path); // Remove the trailing slash if (path.Length > 0 && path[path.Length - 1] == System.IO.Path.DirectorySeparatorChar && path != "." + System.IO.Path.DirectorySeparatorChar) { path = path.TrimEnd(System.IO.Path.DirectorySeparatorChar); } value = path; return(res); }
public void FindMSBuildSDKsPath() { var dotNetCorePath = new DotNetCorePath(); if (dotNetCorePath.IsMissing) { return; } string rootDirectory = Path.GetDirectoryName(dotNetCorePath.FileName); string sdkRootPath = Path.Combine(rootDirectory, "sdk"); if (!Directory.Exists(sdkRootPath)) { return; } string[] directories = Directory.GetDirectories(sdkRootPath); SdksParentDirectory = directories.OrderBy(directory => directory).LastOrDefault(); if (SdksParentDirectory == null) { return; } msbuildSDKsPath = Path.Combine(SdksParentDirectory, "Sdks"); MSBuildProjectService.RegisterProjectImportSearchPath("MSBuildSDKsPath", MSBuildSDKsPath); }
public override void SaveProject(IProgressMonitor monitor, SolutionEntityItem item, MSBuildProject project) { base.SaveProject(monitor, item, project); var dnp = item as DotNetProject; if (dnp == null) { return; } HashSet <string> validProjitems = new HashSet <string> (); foreach (var r in dnp.References.Where(rp => rp.ReferenceType == ReferenceType.Project)) { var ip = r.GetItemsProjectPath(); if (!string.IsNullOrEmpty(ip)) { ip = MSBuildProjectService.ToMSBuildPath(item.ItemDirectory, ip); validProjitems.Add(ip); if (!project.Imports.Any(im => im.Project == ip)) { var im = project.AddNewImport(ip, project.Imports.FirstOrDefault(i => i.Label != "Shared")); im.Label = "Shared"; im.Condition = "Exists('" + ip + "')"; } } } foreach (var im in project.Imports) { if (im.Label == "Shared" && im.Project.EndsWith(".projitems") && !(validProjitems.Contains(im.Project))) { project.RemoveImport(im.Project); } } }
public async Task WriteExtendedProperties() { var tn = new MyProjectTypeNode(); MSBuildProjectService.RegisterCustomItemType(tn); try { var p = Services.ProjectService.CreateProject(tn.Guid); Assert.IsInstanceOf <MyProject> (p); var mp = (MyProject)p; mp.ItemId = "{74FADC4E-C9A8-456E-9A2C-DB933220E073}"; string dir = Util.CreateTmpDir("WriteExtendedProperties"); mp.FileName = Path.Combine(dir, "test.sln"); mp.Data = new MyProjectData { Foo = "bar" }; mp.DataProperty = new MyProjectData { Foo = "rep" }; mp.SimpleData = "Test"; await p.SaveAsync(Util.GetMonitor()); string referenceFile = Util.GetSampleProject("extended-project-properties", "test-data.myproj"); string projectXml1 = File.ReadAllText(referenceFile); string projectXml2 = File.ReadAllText(mp.FileName); Assert.AreEqual(Util.ToWindowsEndings(projectXml1), projectXml2); p.Dispose(); } finally { MSBuildProjectService.UnregisterCustomItemType(tn); } }
public async Task LoadSaveExtendedPropertiesWithUnknownProperty() { // Unknown data should be kept in the file string projFile = Util.GetSampleProject("extended-project-properties", "test-unknown-data.myproj"); string projectXml1 = File.ReadAllText(projFile); var tn = new MyProjectTypeNode(); MSBuildProjectService.RegisterCustomItemType(tn); try { var p = await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile); Assert.IsInstanceOf <MyProject> (p); var mp = (MyProject)p; Assert.NotNull(mp.Data); Assert.AreEqual(mp.Data.Foo, "bar"); Assert.AreEqual(mp.SimpleData, "Test"); await mp.SaveAsync(Util.GetMonitor()); string projectXml2 = File.ReadAllText(projFile); Assert.AreEqual(projectXml1, projectXml2); p.Dispose(); } finally { MSBuildProjectService.UnregisterCustomItemType(tn); } }
public async Task FlavorLoadExtendedProperties_InitialEmptyGroup() { // Check that data load works when it is not defined in the main group // Test for BXC 41774. string projFile = Util.GetSampleProject("extended-project-properties", "test-data-empty-group.myproj"); var tn = new MyEmptyProjectTypeNode(); var fn = new CustomItemNode <FlavorWithData> (); MSBuildProjectService.RegisterCustomItemType(tn); WorkspaceObject.RegisterCustomExtension(fn); try { var p = await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile); Assert.IsInstanceOf <MyEmptyProject> (p); var mp = (MyEmptyProject)p; var f = mp.GetFlavor <FlavorWithData> (); Assert.NotNull(f.Data); Assert.AreEqual(f.Data.Foo, "bar"); Assert.AreEqual(f.SimpleData, "Test"); p.Dispose(); } finally { MSBuildProjectService.UnregisterCustomItemType(tn); WorkspaceObject.UnregisterCustomExtension(fn); } }
public async Task RemoveExtendedProperties() { // Whole ProjectExtensions section should be removed string projFile = Util.GetSampleProject("extended-project-properties", "test-data.myproj"); var tn = new MyProjectTypeNode(); MSBuildProjectService.RegisterCustomItemType(tn); try { var p = await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile); Assert.IsInstanceOf <MyProject> (p); var mp = (MyProject)p; Assert.NotNull(mp.Data); Assert.AreEqual(mp.Data.Foo, "bar"); Assert.AreEqual(mp.SimpleData, "Test"); mp.Data = null; await mp.SaveAsync(Util.GetMonitor()); string projectXml1 = File.ReadAllText(Util.GetSampleProject("extended-project-properties", "test-empty.myproj")); string projectXml2 = File.ReadAllText(projFile); Assert.AreEqual(projectXml1, projectXml2); p.Dispose(); } finally { MSBuildProjectService.UnregisterCustomItemType(tn); } }
public override Gtk.Widget CreatePanelWidget() { bool byDefault, require; MSBuildProjectService.CheckHandlerUsesMSBuildEngine(ConfiguredProject, out byDefault, out require); if (require) { return(null); } var box = new Xwt.VBox { Spacing = 6, Margin = 12 }; box.PackStart(new Xwt.Label { Markup = "<b>Build Engine</b>" }); checkMSBuild = new Xwt.CheckBox(byDefault ? GettextCatalog.GetString("Use MSBuild build engine (recommended for this project type)") : GettextCatalog.GetString("Use MSBuild build engine (unsupported for this project type)")) { Active = ConfiguredProject.UseMSBuildEngine ?? byDefault }; var hbox = new Xwt.HBox { MarginLeft = 18, Spacing = 6 }; hbox.PackStart(checkMSBuild); box.PackStart(hbox); box.Show(); return(box.ToGtkWidget()); }
public void SetValue(FilePath value, bool relativeToProject = true, FilePath relativeToPath = default(FilePath), bool mergeToMainGroup = false) { AssertCanModify(); MergeToMainGroup = mergeToMainGroup; valueType = MSBuildValueType.Path; string baseDir = null; if (relativeToPath != null) { baseDir = relativeToPath; } else if (relativeToProject) { if (ParentProject == null) { // The project has not been set, so we can't calculate the relative path. // Store the full path for now, and set the property type to UnresolvedPath. // When the property gets a value, the relative path will be calculated valueType = MSBuildValueType.UnresolvedPath; SetPropertyValue(value.ToString()); return; } baseDir = ParentProject.BaseDirectory; } // If the path is normalized in the property, keep the value if (!string.IsNullOrEmpty(Value) && new FilePath(MSBuildProjectService.FromMSBuildPath(baseDir, Value)).CanonicalPath == value.CanonicalPath) { return; } SetPropertyValue(MSBuildProjectService.ToMSBuildPath(baseDir, value, false)); }
public void SetValue(string name, FilePath value, FilePath defaultValue = default(FilePath), bool relativeToSolution = true, FilePath relativeToPath = default(FilePath)) { var isDefault = value.CanonicalPath == defaultValue.CanonicalPath; if (isDefault) { // if the value is default, only remove the property if it was not already the default // to avoid unnecessary project file churn if (ContainsKey(name) && (defaultValue == null || defaultValue != GetPathValue(name, relativeToSolution: relativeToSolution, relativeToPath: relativeToPath))) { Remove(name); } return; } string baseDir = null; if (relativeToPath != null) { baseDir = relativeToPath; } else if (relativeToSolution && ParentFile != null && ParentFile.FileName != null) { baseDir = ParentFile.FileName.ParentDirectory; } values [name] = MSBuildProjectService.ToMSBuildPath(baseDir, value, false); }
internal void InitEvaluation(MSBuildProject project) { this.project = project; // Project file properties properties.Add("MSBuildThisFile", Path.GetFileName(project.FileName)); properties.Add("MSBuildThisFileName", project.FileName.FileNameWithoutExtension); properties.Add("MSBuildThisFileExtension", Path.GetExtension(project.FileName)); properties.Add("MSBuildThisFileFullPath", MSBuildProjectService.ToMSBuildPath(null, project.FileName.FullPath)); string dir = Path.GetDirectoryName(project.FileName) + Path.DirectorySeparatorChar; properties.Add("MSBuildThisFileDirectory", MSBuildProjectService.ToMSBuildPath(null, dir)); properties.Add("MSBuildThisFileDirectoryNoRoot", MSBuildProjectService.ToMSBuildPath(null, dir.Substring(Path.GetPathRoot(dir).Length))); // Properties only set for the root project, not for imported projects if (parentContext == null) { properties.Add("VisualStudioReferenceAssemblyVersion", project.ToolsVersion + ".0.0"); properties.Add("MSBuildProjectDefaultTargets", project.DefaultTargets); properties.Add("MSBuildProjectExtension", Path.GetExtension(project.FileName)); properties.Add("MSBuildProjectFile", project.FileName.FileName); properties.Add("MSBuildProjectFullPath", MSBuildProjectService.ToMSBuildPath(null, project.FileName.FullPath.ToString())); properties.Add("MSBuildProjectName", project.FileName.FileNameWithoutExtension); dir = project.BaseDirectory.IsNullOrEmpty ? Environment.CurrentDirectory : project.BaseDirectory.ToString(); properties.Add("MSBuildProjectDirectory", MSBuildProjectService.ToMSBuildPath(null, dir)); properties.Add("MSBuildProjectDirectoryNoRoot", MSBuildProjectService.ToMSBuildPath(null, dir.Substring(Path.GetPathRoot(dir).Length))); InitEngineProperties(project.TargetRuntime ?? Runtime.SystemAssemblyService.DefaultRuntime, properties, out searchPaths); } }
public async Task BuildDotNetCoreProjectWithImportUsingMSBuildSDKsPathProperty() { // This test is being ignored for now because relying on MSBuildSDKsPath is not entirely correct, // the correct approach is to use the Sdk attribute in the import. // In any case this currently works for web projects because MSBuildSDKsPath ends being resolved // to the Mono's msbuild dir, which has the web targets. FilePath solFile = Util.GetSampleProject("dotnetcore-console", "dotnetcore-msbuildsdkspath-import.sln"); FilePath sdksPath = solFile.ParentDirectory.Combine("Sdks"); MSBuildProjectService.RegisterProjectImportSearchPath("MSBuildSDKsPath", sdksPath); try { var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); var p = (Project)sol.Items [0]; p.DefaultConfiguration = new DotNetProjectConfiguration("Debug") { OutputAssembly = p.BaseDirectory.Combine("bin", "test.dll") }; var res = await p.RunTarget(Util.GetMonitor(), "Build", ConfigurationSelector.Default); var buildResult = res.BuildResult; Assert.AreEqual(1, buildResult.Errors.Count); string expectedMessage = string.Format("Something failed (test-import.targets): {0}", sdksPath); Assert.AreEqual(expectedMessage, buildResult.Errors [0].ErrorText); sol.Dispose(); } finally { MSBuildProjectService.UnregisterProjectImportSearchPath("MSBuildSDKsPath", sdksPath); } }
internal protected override void OnReadProject(ProgressMonitor monitor, MSBuildProject msproject) { base.OnReadProject(monitor, msproject); // Convert .projitems imports into project references foreach (var sp in msproject.Imports.Where(im => im.Label == "Shared" && im.Project.EndsWith(".projitems"))) { var projitemsFile = sp.Project; if (!string.IsNullOrEmpty(projitemsFile)) { projitemsFile = MSBuildProjectService.FromMSBuildPath(Project.ItemDirectory, projitemsFile); projitemsFile = Path.Combine(Path.GetDirectoryName(msproject.FileName), projitemsFile); if (File.Exists(projitemsFile)) { using (MSBuildProject p = new MSBuildProject(msproject.EngineManager)) { p.Load(projitemsFile); Project.LoadProjectItems(p, ProjectItemFlags.Hidden | ProjectItemFlags.DontPersist, null); var r = ProjectReference.CreateProjectReference(projitemsFile); r.Flags = ProjectItemFlags.DontPersist; r.SetItemsProjectPath(projitemsFile); Project.References.Add(r); } } } } }
internal void ResolvePath() { if (valueType == MSBuildValueType.UnresolvedPath) { var val = Value; SetPropertyValue(MSBuildProjectService.ToMSBuildPath(ParentProject.BaseDirectory, val, false)); } }
internal protected override void Write(Project project, MSBuildItem buildItem) { if (string.IsNullOrEmpty(Include)) { Include = MSBuildProjectService.ToMSBuildPath(project.ItemDirectory, Path); } base.Write(project, buildItem); }
void ReadProjectReference(Project project, IMSBuildItemEvaluated buildItem) { // Get the project name from the path, since the Name attribute may other stuff other than the name string path = MSBuildProjectService.FromMSBuildPath(project.ItemDirectory, buildItem.Include); string name = buildItem.Metadata.GetValue("Name", Path.GetFileNameWithoutExtension(path)); string projectGuid = buildItem.Metadata.GetValue("Project"); Init(ReferenceType.Project, name, null, projectGuid); }
protected override void OnReadProject(ProgressMonitor monitor, MSBuildProject msproject) { base.OnReadProject(monitor, msproject); var import = msproject.Imports.FirstOrDefault(im => im.Label == "Shared"); if (import == null) { // Sanity check. if (!StringComparer.OrdinalIgnoreCase.Equals(msproject.FileName.Extension, FileName.Extension)) { // ProjectTypeGuid mismatch in solution file. throw new InvalidOperationException(GettextCatalog.GetString( "Project {0} is being loaded as a Shared Assets project but has a different file extension. Please check the project type GUID in the solution file is correct.", Name)); } return; } // TODO: load the type from msbuild foreach (var item in msproject.Imports) { if (item.Project.Equals(CSharptargets, StringComparison.OrdinalIgnoreCase)) { LanguageName = "C#"; break; } if (item.Project.Equals(FSharptargets, StringComparison.OrdinalIgnoreCase)) { LanguageName = "F#"; break; } } //If for some reason the language name is empty default it to C# if (String.IsNullOrEmpty(LanguageName)) { LanguageName = "C#"; } projItemsPath = MSBuildProjectService.FromMSBuildPath(msproject.BaseDirectory, import.Project); MSBuildProject p = new MSBuildProject(msproject.EngineManager); p.Load(projItemsPath); p.Evaluate(); var cp = p.PropertyGroups.FirstOrDefault(g => g.Label == "Configuration"); if (cp != null) { DefaultNamespace = cp.GetValue("Import_RootNamespace"); } LoadProjectItems(p, ProjectItemFlags.None, usedMSBuildItems); projitemsProject = p; }
public void DefaultMSBuildSupport() { DotNetAssemblyProject project = new DotNetAssemblyProject("C#"); bool byDefault, require; MSBuildProjectService.CheckHandlerUsesMSBuildEngine(project, out byDefault, out require); Assert.IsTrue(byDefault); Assert.IsFalse(require); }
static string NormalizeFolder(FilePath baseDirectory, string folder) { if (IsClearKeyword(folder)) { return(folder); } return(MSBuildProjectService.FromMSBuildPath(baseDirectory, folder)); }
public override async Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid) { if (CanRead(fileName, typeof(SolutionItem))) { return(await MSBuildProjectService.LoadItem(monitor, fileName, MSBuildFileFormat.VS2012, typeGuid, itemGuid, ctx)); } throw new NotSupportedException(); }
public void FormatConversions() { Solution sol = TestProjectsChecks.CreateConsoleSolution("reloading"); Project p = (Project)sol.Items [0]; Assert.AreEqual(Services.ProjectService.DefaultFileFormat.Id, sol.FileFormat.Id); Assert.AreEqual(Services.ProjectService.DefaultFileFormat.Id, p.FileFormat.Id); Assert.AreEqual("4.0", MSBuildProjectService.GetHandler(p).ToolsVersion); // Change solution format of unsaved solution sol.ConvertToFormat(Util.FileFormatMSBuild08, true); Assert.AreEqual("MSBuild08", sol.FileFormat.Id); Assert.AreEqual("MSBuild08", p.FileFormat.Id); Assert.AreEqual("3.5", MSBuildProjectService.GetHandler(p).ToolsVersion); sol.ConvertToFormat(Util.FileFormatMSBuild10, true); Assert.AreEqual("MSBuild10", sol.FileFormat.Id); Assert.AreEqual("MSBuild10", p.FileFormat.Id); Assert.AreEqual("4.0", MSBuildProjectService.GetHandler(p).ToolsVersion); // Change solution format of saved solution sol.Save(Util.GetMonitor()); sol.ConvertToFormat(Util.FileFormatMSBuild05, false); Assert.AreEqual("MSBuild05", sol.FileFormat.Id); Assert.AreEqual("MSBuild05", p.FileFormat.Id); Assert.AreEqual("2.0", MSBuildProjectService.GetHandler(p).ToolsVersion); // Add new project Project newp = new DotNetAssemblyProject("C#"); Assert.AreEqual("MSBuild12", newp.FileFormat.Id); Assert.AreEqual("4.0", MSBuildProjectService.GetHandler(newp).ToolsVersion); sol.RootFolder.Items.Add(newp); Assert.AreEqual("MSBuild05", newp.FileFormat.Id); Assert.AreEqual("2.0", MSBuildProjectService.GetHandler(newp).ToolsVersion); // Add saved project string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); Solution msol = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); Project mp = (Project)msol.Items [0]; Assert.AreEqual("MSBuild05", mp.FileFormat.Id); sol.RootFolder.Items.Add(newp); Assert.AreEqual("MSBuild05", mp.FileFormat.Id); }
static PackageSource CreatePackageSource(FilePath baseDirectory, string source) { if (!IsClearKeyword(source)) { source = MSBuildProjectService.UnescapePath(source); source = UriUtility.GetAbsolutePath(baseDirectory, source); } return(new PackageSource(source)); }