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; }
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 static void AddImportIfMissing(this MSBuildProject project, string name, string condition = null) { var existing = project.GetImport(name, condition); if (existing == null) { project.AddNewImport(name, condition); } }
void AddPackagingPropsImport(MSBuildProject msproject) { MSBuildObject insertBefore = msproject.GetAllObjects().FirstOrDefault(); msproject.AddNewImport( @"$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.props", @"Exists('$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.props')", insertBefore); }
void AddPackagingTargetsImport(MSBuildProject msproject) { // Create dummy new msbuild object to ensure import is added as last child. var insertBefore = new MSBuildItem(); msproject.AddNewImport( @"$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.targets", @"Exists('$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.targets')", insertBefore); }
public static void AddImport( this MSBuildProject project, string importedProjectFile, ImportLocation importLocation, string condition) { var before = importLocation == ImportLocation.Top ? project.GetAllObjects().FirstOrDefault() : null; project.AddNewImport(importedProjectFile, condition, before); }
public static void AddImport( this MSBuildProject project, string importedProjectFile, ImportLocation importLocation, string condition) { MSBuildObject before = GetInsertBeforeObject(project, importLocation); project.AddNewImport(importedProjectFile, condition, before); }
public void StartWhitespaceForImportInsertedAsLastImport() { string projectFile = Util.GetSampleProject("ConsoleApp-VS2013", "ConsoleApplication.csproj"); var p = new MSBuildProject(); p.Load(projectFile); p.Evaluate(); MSBuildImport import = p.AddNewImport("MyImport.targets", beforeObject: null); Assert.AreEqual(p.TextFormat.NewLine, p.StartWhitespace); Assert.AreEqual(" ", import.StartWhitespace); }
internal protected override void OnWriteProject(ProgressMonitor monitor, MSBuildProject project) { base.OnWriteProject(monitor, project); HashSet <string> validProjitems = new HashSet <string> (); foreach (var r in Project.References.Where(rp => rp.ReferenceType == ReferenceType.Project)) { var ip = r.GetItemsProjectPath(); if (!string.IsNullOrEmpty(ip)) { ip = MSBuildProjectService.ToMSBuildPath(Project.ItemDirectory, ip); validProjitems.Add(ip); if (!project.Imports.Any(im => im.Project == ip)) { // If there is already a Shared import, place the new import in the same location MSBuildObject before = project.Imports.FirstOrDefault(i => i.Label == "Shared" && i.Project.EndsWith(".projitems")); if (before == null) { var fsharpProject = project.ProjectTypeGuids.Contains("{F2A71F9B-5D33-465A-A702-920D77279786}"); if (fsharpProject) { //For F# use the first item group as the shared project files have to be listed first before = project.ItemGroups.FirstOrDefault(i => i.Label != "Shared"); } else { before = project.Imports.FirstOrDefault(i => i.Label != "Shared"); } } var im = project.AddNewImport(ip, beforeObject: before); im.Label = "Shared"; im.Condition = "Exists('" + ip + "')"; } } } foreach (var im in project.Imports.ToArray()) { if (im.Label == "Shared" && im.Project.EndsWith(".projitems") && !(validProjitems.Contains(im.Project))) { project.RemoveImport(im.Project); } } }
public void AddImportIfMissing_AddImportToBottomWhenOtherImportIsNotLastElementInProject_ImportAddedAsLastElementInProject() { CreateProject(); var itemGroup = project.AddNewItemGroup(); itemGroup.AddNewItem("File.cs", "File.cs"); project.AddNewImport("test", null, itemGroup); string importFile = @"..\packages\Foo.0.1\build\Foo.targets"; string condition = "Exists('..\\packages\\Foo.0.1\\build\\Foo.targets')"; var lastItemBeforeAddingNewImport = project.GetAllObjects().Last() as MSBuildItemGroup; AddImportIfMissingAtBottom(importFile, condition); var lastItem = project.GetAllObjects().Last() as MSBuildImport; Assert.IsNotNull(lastItem); Assert.AreEqual(importFile, lastItem.Project); Assert.AreEqual(condition, lastItem.Condition); Assert.IsNotNull(lastItemBeforeAddingNewImport); Assert.AreEqual("File.cs", lastItemBeforeAddingNewImport.Items.First().Include); }
static bool UpgradeMonoGameProject(MonoDevelop.Core.IProgressMonitor monitor, MonoDevelop.Projects.SolutionEntityItem item, MSBuildProject project) { bool needsSave = false; bool containsMGCB = project.ItemGroups.Any(x => x.Items.Any(i => System.IO.Path.GetExtension(i.Include) == ".mgcb")); bool isMonoGame = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "MonoGamePlatform")) || project.ItemGroups.Any(x => x.Items.Any(i => i.Name == "Reference" && i.Include == "MonoGame.Framework")) || containsMGCB; bool isApplication = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "OutputType" && p.GetValue() == "Exe")) || project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "AndroidApplication" && string.Compare(p.GetValue(), bool.TrueString, true) == 0)); bool isShared = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "HasSharedItems" && p.GetValue() == "true")); var type = item.GetType().Name; monitor.Log.WriteLine("Found {0}", type); var platform = Environment.OSVersion.Platform == PlatformID.Win32NT ? "Windows" : "DesktopGL"; var path = MonoGameExtensionsPath; switch (type) { case "XamarinIOSProject": platform = "iOS"; break; case "MonoDroidProject": platform = "Android"; break; case "XamMac2Project": case "MonoGameProject": platform = "DesktopGL"; break; case "XamMac": case "XamMacProject": platform = "DesktopGL"; // Xamarin.Mac Classic does not use MSBuild so we need to absolute path. path = MonoGameExtensionsAbsolutePath; break; case "MonoMac": case "MonoMacProject": platform = "MacOSX"; // Xamarin.Mac Classic does not use MSBuild so we need to absolute path. path = MonoGameExtensionsAbsolutePath; break; } monitor.Log.WriteLine("Platform = {0}", platform); monitor.Log.WriteLine("Path = {0}", path); monitor.Log.WriteLine("isMonoGame {0}", isMonoGame); if (isMonoGame) { var ritems = new List <MSBuildItem> (); foreach (var ig in project.ItemGroups) { foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "MonoGame.Framework")) { if (!i.HasMetadata("HintPath")) { monitor.Log.WriteLine("Fixing {0} to be MonoGameContentReference", i.Include); var a = ig.AddNewItem("Reference", i.Include); a.SetMetadata("HintPath", string.Format(path, platform, "MonoGame.Framework.dll")); ritems.Add(i); needsSave = true; } } foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "Tao.Sdl")) { if (!i.HasMetadata("HintPath")) { monitor.Log.WriteLine("Fixing {0} to be Tao.Sdl", i.Include); var a = ig.AddNewItem("Reference", i.Include); a.SetMetadata("HintPath", string.Format(path, platform, "Tao.Sdl.dll")); ritems.Add(i); needsSave = true; } } foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include.StartsWith("OpenTK") && (platform != "iOS" && platform != "Android"))) { if (!i.HasMetadata("HintPath")) { monitor.Log.WriteLine("Fixing {0} to be OpenTK", i.Include); var a = ig.AddNewItem("Reference", i.Include); a.SetMetadata("HintPath", string.Format(path, platform, "OpenTK.dll")); a.SetMetadata("SpecificVersion", "true"); ritems.Add(i); needsSave = true; } } foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "NVorbis")) { if (!i.HasMetadata("HintPath")) { monitor.Log.WriteLine("Fixing {0} to be NVorbis", i.Include); var a = ig.AddNewItem("Reference", i.Include); a.SetMetadata("HintPath", string.Format(path, platform, "NVorbis.dll")); ritems.Add(i); needsSave = true; } } } foreach (var a in ritems) { project.RemoveItem(a); } var dotNetProject = item as DotNetProject; if (dotNetProject != null && (type == "MonoMacProject" || type == "XamMacProject")) { var items = new List <ProjectReference> (); var newitems = new List <ProjectReference> (); foreach (var reference in dotNetProject.References) { if (reference.Reference == "MonoGame.Framework" && string.IsNullOrEmpty(reference.HintPath)) { items.Add(reference); newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "MonoGame.Framework.dll"))); } if (reference.Reference.StartsWith("OpenTK") && string.IsNullOrEmpty(reference.HintPath)) { items.Add(reference); newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "OpenTK.dll"))); } if (reference.Reference == "NVorbis" && string.IsNullOrEmpty(reference.HintPath)) { items.Add(reference); newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "NVorbis.dll"))); } if (reference.Reference == "Tao.Sdl" && string.IsNullOrEmpty(reference.HintPath)) { items.Add(reference); newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "Tao.Sdl.dll"))); } } dotNetProject.References.RemoveRange(items); dotNetProject.References.AddRange(newitems); } } if (isMonoGame && containsMGCB && (isApplication || isShared)) { if (!project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "MonoGamePlatform")) && !isShared) { monitor.Log.WriteLine("Adding MonoGamePlatform", platform); project.PropertyGroups.First().SetPropertyValue("MonoGamePlatform", platform, true); needsSave = true; } if (!project.Imports.Any(x => x.Project.StartsWith(MonoGameCommonProps, StringComparison.OrdinalIgnoreCase)) && !isShared) { monitor.Log.WriteLine("Adding MonoGame.Common.props Import"); var e = project.Document.DocumentElement; var manager = new XmlNamespaceManager(new NameTable()); var schema = "http://schemas.microsoft.com/developer/msbuild/2003"; manager.AddNamespace("tns", schema); var import = project.Document.CreateElement("Import", schema); import.SetAttribute("Project", MonoGameCommonProps); import.SetAttribute("Condition", string.Format("Exists('{0}')", MonoGameCommonProps)); project.Document.DocumentElement.InsertBefore(import, project.Document.DocumentElement.FirstChild); needsSave = true; } if (containsMGCB) { var ritems = new List <MSBuildItem> (); foreach (var ig in project.ItemGroups) { foreach (var i in ig.Items.Where(x => System.IO.Path.GetExtension(x.Include) == ".mgcb")) { if (i.Name != "MonoGameContentReference" && i.Name == "None") { monitor.Log.WriteLine("Fixing {0} to be MonoGameContentReference", i.Include); ig.AddNewItem("MonoGameContentReference", i.Include); ritems.Add(i); needsSave = true; } } } foreach (var a in ritems) { project.RemoveItem(a); } } if (!project.Imports.Any(x => x.Project.StartsWith(MonoGameContentBuildTargets, StringComparison.OrdinalIgnoreCase)) && !isShared) { monitor.Log.WriteLine("Adding MonoGame Content Builder .targets"); project.AddNewImport(MonoGameContentBuildTargets); needsSave = true; } } return(needsSave); }
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); }
void AddImport(string name, string condition, MSBuildObject before = null) { msbuildProject.AddNewImport(name, condition, before); }
static bool UpgradeMonoGameProject(MonoDevelop.Core.IProgressMonitor monitor, MonoDevelop.Projects.SolutionEntityItem item, MSBuildProject project) { bool needsSave = false; bool containsMGCB = project.ItemGroups.Any(x => x.Items.Any(i => System.IO.Path.GetExtension(i.Include) == ".mgcb")); bool isMonoGame = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "MonoGamePlatform")) || project.ItemGroups.Any(x => x.Items.Any(i => i.Name == "Reference" && i.Include == "MonoGame.Framework")) || containsMGCB; bool isApplication = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "OutputType" && p.GetValue() == "Exe")) || project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "AndroidApplication" && string.Compare(p.GetValue(), bool.TrueString, true) == 0)); bool isShared = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "HasSharedItems" && p.GetValue() == "true")); var type = item.GetType().Name; var platform = Environment.OSVersion.Platform == PlatformID.Win32NT ? "Windows" : "DesktopGL"; switch (type) { case "XamarinIOSProject": platform = "iOS"; break; case "MonoDroidProject": platform = "Android"; break; case "MonoGameProject": platform = "DesktopGL"; break; } if (isMonoGame) { var ritems = new List <MSBuildItem> (); foreach (var ig in project.ItemGroups) { foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "MonoGame.Framework")) { if (!i.HasMetadata("HintPath")) { monitor.Log.WriteLine("Fixing {0} to be MonoGameContentReference", i.Include); var a = ig.AddNewItem("Reference", i.Include); a.SetMetadata("HintPath", string.Format(@"$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\{0}\MonoGame.Framework.dll", platform)); ritems.Add(i); needsSave = true; } } } foreach (var a in ritems) { project.RemoveItem(a); } } if (isMonoGame && containsMGCB && (isApplication || isShared)) { if (!project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "MonoGamePlatform")) && !isShared) { monitor.Log.WriteLine("Adding MonoGamePlatform", platform); project.PropertyGroups.First().SetPropertyValue("MonoGamePlatform", platform, true); needsSave = true; } if (!project.Imports.Any(x => x.Project.StartsWith(MonoGameCommonProps, StringComparison.OrdinalIgnoreCase)) && !isShared) { monitor.Log.WriteLine("Adding MonoGame.Common.props Import"); var e = project.Document.DocumentElement; var manager = new XmlNamespaceManager(new NameTable()); var schema = "http://schemas.microsoft.com/developer/msbuild/2003"; manager.AddNamespace("tns", schema); var import = project.Document.CreateElement("Import", schema); import.SetAttribute("Project", MonoGameCommonProps); import.SetAttribute("Conditon", string.Format("Exists('{0}')", MonoGameCommonProps)); project.Document.DocumentElement.InsertBefore(import, project.Document.DocumentElement.FirstChild); needsSave = true; } if (containsMGCB) { var ritems = new List <MSBuildItem> (); foreach (var ig in project.ItemGroups) { foreach (var i in ig.Items.Where(x => System.IO.Path.GetExtension(x.Include) == ".mgcb")) { if (i.Name != "MonoGameContentReference" && i.Name == "None") { monitor.Log.WriteLine("Fixing {0} to be MonoGameContentReference", i.Include); ig.AddNewItem("MonoGameContentReference", i.Include); ritems.Add(i); needsSave = true; } } } foreach (var a in ritems) { project.RemoveItem(a); } } if (!project.Imports.Any(x => x.Project.StartsWith(MonoGameContentBuildTargets, StringComparison.OrdinalIgnoreCase)) && !isShared) { monitor.Log.WriteLine("Adding MonoGame Content Builder .targets"); project.AddNewImport(MonoGameContentBuildTargets); needsSave = true; } } return(needsSave); }
static bool UpgradeMonoGameProject(MonoDevelop.Core.ProgressMonitor monitor, DotNetProjectExtension extension, MSBuildProject project) { bool needsSave = false; bool containsMGCB = project.ItemGroups.Any(x => x.Items.Any(i => System.IO.Path.GetExtension(i.Include) == ".mgcb")); bool isMonoGame = project.PropertyGroups.Any(x => x.GetProperties().Any(p => p.Name == "MonoGamePlatform")) || project.ItemGroups.Any(x => x.Items.Any(i => i.Name == "Reference" && i.Include == "MonoGame.Framework")) || containsMGCB; bool isDesktopGL = project.ItemGroups.Any(x => x.Items.Any(i => i.Include.EndsWith("SDL2.dll"))); bool isApplication = project.PropertyGroups.Any(x => x.GetProperties().Any(p => p.Name == "OutputType" && p.Value == "Exe")) | project.PropertyGroups.Any(x => x.GetProperties().Any(p => p.Name == "AndroidApplication" && string.Compare(p.Value, bool.TrueString, true) == 0)); bool isShared = project.PropertyGroups.Any(x => x.GetProperties().Any(p => p.Name == "HasSharedItems" && p.Value == "true")); bool absoluteReferenes = false; var type = extension.Project.GetType().Name; monitor.Log.WriteLine("Found {0}", type); monitor.Log.WriteLine("Found {0}", project.GetType().Name); var platform = isDesktopGL ? "DesktopGL" : "Windows"; var path = MonoGameExtensionsPath; if (extension.Project.FlavorGuids.Contains("{FEACFBD2-3405-455C-9665-78FE426C6842}")) { platform = "iOS"; } if (extension.Project.FlavorGuids.Contains("{06FA79CB-D6CD-4721-BB4B-1BD202089C55}")) { platform = "tvOS"; } if (extension.Project.FlavorGuids.Contains("{EFBA0AD7-5A72-4C68-AF49-83D382785DCF}")) { platform = "Android"; } if (extension.Project.FlavorGuids.Contains("{948B3504-5B70-4649-8FE4-BDE1FB46EC69}")) { platform = "MacOSX"; // MonoMac Classic does not use MSBuild so we need to absolute path. path = MonoGameExtensionsAbsolutePath; absoluteReferenes = true; } if (extension.Project.FlavorGuids.Contains("{42C0BBD9-55CE-4FC1-8D90-A7348ABAFB23}")) { platform = "DesktopGL"; // Xamarin.Mac Classic does not use MSBuild so we need to absolute path. path = MonoGameExtensionsAbsolutePath; absoluteReferenes = true; } if (extension.Project.FlavorGuids.Contains("{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1}")) { platform = "DesktopGL"; } monitor.Log.WriteLine("Platform = {0}", platform); monitor.Log.WriteLine("Path = {0}", path); monitor.Log.WriteLine("isMonoGame {0}", isMonoGame); if (isMonoGame) { var ritems = new List <MSBuildItem> (); foreach (var ig in project.ItemGroups) { foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "MonoGame.Framework")) { var metaData = i.Metadata; if (!metaData.HasProperty("HintPath")) { monitor.Log.WriteLine("Fixing {0} to be MonoGameContentReference", i.Include); metaData.SetValue("HintPath", string.Format(path, platform, "MonoGame.Framework.dll")); needsSave = true; } } foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "Tao.Sdl")) { var metaData = i.Metadata; if (!metaData.HasProperty("HintPath")) { monitor.Log.WriteLine("Fixing {0} to be Tao.Sdl", i.Include); metaData.SetValue("HintPath", string.Format(path, platform, "Tao.Sdl.dll")); needsSave = true; } } foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include.StartsWith("OpenTK") && (platform != "iOS" && platform != "Android"))) { var metaData = i.Metadata; if (!metaData.HasProperty("HintPath")) { monitor.Log.WriteLine("Fixing {0} to be OpenTK", i.Include); metaData.SetValue("HintPath", string.Format(path, platform, "OpenTK.dll")); metaData.SetValue("SpecificVersion", "true"); needsSave = true; } } } foreach (var a in ritems) { project.RemoveItem(a); } var dotNetProject = extension.Project; if (dotNetProject != null && absoluteReferenes) { var items = new List <ProjectReference> (); var newitems = new List <ProjectReference> (); foreach (var reference in dotNetProject.References) { if (reference.Reference == "MonoGame.Framework" && string.IsNullOrEmpty(reference.HintPath)) { items.Add(reference); newitems.Add(ProjectReference.CreateCustomReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "MonoGame.Framework.dll"))); } if (reference.Reference.StartsWith("OpenTK", StringComparison.OrdinalIgnoreCase) && string.IsNullOrEmpty(reference.HintPath)) { items.Add(reference); newitems.Add(ProjectReference.CreateCustomReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "OpenTK.dll"))); } if (reference.Reference == "Tao.Sdl" && string.IsNullOrEmpty(reference.HintPath)) { items.Add(reference); newitems.Add(ProjectReference.CreateCustomReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "Tao.Sdl.dll"))); } } dotNetProject.References.RemoveRange(items); dotNetProject.References.AddRange(newitems); } } if (isMonoGame && containsMGCB && (isApplication || isShared)) { if (!project.PropertyGroups.Any(x => x.GetProperties().Any(p => p.Name == "MonoGamePlatform")) && !isShared) { monitor.Log.WriteLine("Adding MonoGamePlatform {0}", platform == "tvOS" ? "iOS" : platform); project.PropertyGroups.First().SetValue("MonoGamePlatform", platform == "tvOS" ? "iOS" : platform, true); needsSave = true; } if (!project.Imports.Any(x => x.Project.StartsWith(MonoGameCommonProps, StringComparison.OrdinalIgnoreCase)) && !isShared) { monitor.Log.WriteLine("Adding MonoGame.Common.props Import"); project.AddNewImport(MonoGameCommonProps, string.Format("Exists('{0}')", MonoGameCommonProps), project.PropertyGroups.First()); needsSave = true; } if (containsMGCB) { var ritems = new List <MSBuildItem> (); foreach (var ig in project.ItemGroups) { foreach (var i in ig.Items.Where(x => System.IO.Path.GetExtension(x.Include) == ".mgcb")) { if (i.Name != "MonoGameContentReference" && i.Name == "None") { monitor.Log.WriteLine("Fixing {0} to be MonoGameContentReference", i.Include); ig.AddNewItem("MonoGameContentReference", i.Include); ritems.Add(i); needsSave = true; } } } foreach (var a in ritems) { project.RemoveItem(a); } } if (!project.Imports.Any(x => x.Project.StartsWith(MonoGameContentBuildTargets, StringComparison.OrdinalIgnoreCase)) && !isShared) { monitor.Log.WriteLine("Adding MonoGame Content Builder .targets"); project.AddNewImport(MonoGameContentBuildTargets); needsSave = true; } } return(needsSave); }