public void Execute_ReferenceBeingUpdatedHasLocalCopyFalseButCaseIsDifferent_ReferenceAddedHasLocalCopyFalse() { var originalProjectReference = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "nunit.framework"); originalProjectReference.LocalCopy = false; CreateAction("MyProject", originalProjectReference); AddInstallPackageIntoProjectAction("Test", "1.2"); var firstReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NewAssembly"); firstReferenceBeingAdded.LocalCopy = true; var secondReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NUnit.Framework"); packageManager.BeforeExecuteActionTask = async() => { packageManagementEvents.OnReferenceRemoving(originalProjectReference); await nugetProject.ProjectReferenceMaintainer.RemoveReference(originalProjectReference); packageManagementEvents.OnReferenceAdding(firstReferenceBeingAdded); await nugetProject.ProjectReferenceMaintainer.AddReference(firstReferenceBeingAdded); packageManagementEvents.OnReferenceAdding(secondReferenceBeingAdded); await nugetProject.ProjectReferenceMaintainer.AddReference(secondReferenceBeingAdded); }; action.Execute(); var nunitFrameworkReference = project.References.FirstOrDefault(r => r.Reference == originalProjectReference.Reference); var newReference = project.References.FirstOrDefault(r => r.Reference == "NewAssembly"); Assert.IsTrue(newReference.LocalCopy); Assert.IsFalse(nunitFrameworkReference.LocalCopy); }
public ProjectReference Create() { var refType = elem.GetAttribute("type"); var projectReference = ProjectReference.CreateCustomReference((ReferenceType)Enum.Parse(typeof(ReferenceType), refType), elem.GetAttribute("refto")); var hintPath = GetMSBuildReferenceHintPath(); if (hintPath != null) { projectReference.Metadata.SetValue("HintPath", hintPath); } string specificVersion = elem.GetAttribute("SpecificVersion"); if (!string.IsNullOrEmpty(specificVersion)) { projectReference.SpecificVersion = bool.Parse(specificVersion); } string localCopy = elem.GetAttribute("LocalCopy"); if (!string.IsNullOrEmpty(localCopy) && projectReference.CanSetLocalCopy) { projectReference.LocalCopy = bool.Parse(localCopy); } string referenceOutputAssembly = elem.GetAttribute("ReferenceOutputAssembly"); if (!string.IsNullOrEmpty(referenceOutputAssembly)) { projectReference.ReferenceOutputAssembly = bool.Parse(referenceOutputAssembly); } return(projectReference); }
public void Execute_PackageAlreadyExistsWhenInstallingItAgainAndReferenceBeingInstalledOriginallyHadLocalCopyFalse_ReferenceAddedHasLocalCopyFalse() { var originalProjectReference = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "nunit.framework"); originalProjectReference.LocalCopy = false; CreateAction("Test", "2.1", originalProjectReference); action.PreserveLocalCopyReferences = true; var firstReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NewAssembly"); var secondReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NUnit.Framework"); packageManager.BeforeExecuteActionTask = async() => { await nugetProject.ProjectReferenceMaintainer.RemoveReference(originalProjectReference); packageManagementEvents.OnReferenceRemoving(originalProjectReference); packageManagementEvents.OnReferenceAdding(firstReferenceBeingAdded); await nugetProject.ProjectReferenceMaintainer.AddReference(firstReferenceBeingAdded); packageManagementEvents.OnReferenceAdding(secondReferenceBeingAdded); await nugetProject.ProjectReferenceMaintainer.AddReference(secondReferenceBeingAdded); }; action.Execute(); var nunitFrameworkReference = project.References.FirstOrDefault(r => r.Reference == originalProjectReference.Reference); var newReference = project.References.FirstOrDefault(r => r.Reference == "NewAssembly"); Assert.IsTrue(newReference.LocalCopy); Assert.IsFalse(nunitFrameworkReference.LocalCopy); Assert.IsTrue(action.PreserveLocalCopyReferences); }
public void Execute_ReferenceHasLocalCopyFalseWhenUninstalled_ReferenceHasLocalCopyFalseAfterBeingReinstalled() { CreateAction("MyPackage", "1.2.3.4"); FakePackage package = AddPackageToSourceRepository("MyPackage", "1.2.3.4"); var firstReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NewAssembly"); var secondReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NUnit.Framework"); project.FakeUninstallPackageAction.ExecuteAction = () => { var referenceBeingRemoved = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NUnit.Framework"); referenceBeingRemoved.LocalCopy = false; packageManagementEvents.OnReferenceRemoving(referenceBeingRemoved); }; bool installActionMaintainsLocalCopyReferences = false; project.InstallPackageExecuteAction = () => { installActionMaintainsLocalCopyReferences = project.LastInstallPackageCreated.PreserveLocalCopyReferences; packageManagementEvents.OnReferenceAdding(firstReferenceBeingAdded); packageManagementEvents.OnReferenceAdding(secondReferenceBeingAdded); }; action.Execute(); Assert.IsTrue(firstReferenceBeingAdded.LocalCopy); Assert.IsFalse(secondReferenceBeingAdded.LocalCopy); Assert.IsFalse(installActionMaintainsLocalCopyReferences, "Should be false since the reinstall action will maintain the local copies"); }
FakeDotNetProject AddProjectReference(string projectName, string fileName, string include) { fileName = fileName.ToNativePath(); var projectReference = ProjectReference.CreateCustomReference(ReferenceType.Project, include); project.References.Add(projectReference); var fakeOtherProject = new FakeDotNetProject(fileName); fakeOtherProject.Name = projectName; solution.Projects.Add(fakeOtherProject); return(fakeOtherProject); }
void AddProjectReference(string fileName) { DnxProject project = ParentSolution.FindProjectByProjectJsonFileName(fileName); if (project != null) { var projectItem = ProjectReference.CreateCustomReference(ReferenceType.Project, project.Name); Project.References.Add(projectItem); } else { LoggingService.LogDebug("Unable to find project by json filename '{0}'.", fileName); } }
public async Task ProjectModifiedWhilstBeingAddedToSolution() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile)) { try { var workspace = await TypeSystemServiceTestExtensions.LoadSolution(sol); var project = new ModifyReferencesDuringGetSourceFilesDotNetProject(); project.FileName = Path.Combine(sol.BaseDirectory, "ProjectModifiedWhilstBeingAddedToSolution.csproj"); await project.SaveAsync(Util.GetMonitor()); var reference = ProjectReference.CreateCustomReference(ReferenceType.Package, "System.ComponentModel.Composition"); var assemblyFileName = typeof(System.Xml.Linq.XName).Assembly.Location; project.AddExtraReference(new AssemblyReference(assemblyFileName)); var projectLoadedTask = new TaskCompletionSource <bool> (); workspace.WorkspaceChanged += (sender, e) => { if (e.Kind == Microsoft.CodeAnalysis.WorkspaceChangeKind.ProjectReloaded) { projectLoadedTask.TrySetResult(true); } }; sol.RootFolder.AddItem(project); if (await Task.WhenAny(projectLoadedTask.Task, Task.Delay(5000)) != projectLoadedTask.Task) { Assert.Fail("Timeout waiting for project to be reloaded by the type system service."); } var projectId = workspace.GetProjectId(project); var projectInfo = workspace.CurrentSolution.GetProject(projectId); var metadataReference = projectInfo.MetadataReferences .OfType <Microsoft.CodeAnalysis.PortableExecutableReference> () .FirstOrDefault(r => r.FilePath.EndsWith("System.Xml.Linq.dll", StringComparison.Ordinal)); Assert.IsNotNull(metadataReference, "System.Xml.Linq reference missing from type system information"); } finally { TypeSystemServiceTestExtensions.UnloadSolution(sol); } } }
public void Execute_PreserveLocalCopyReferencesSetToFalse_ReferenceThatOriginallyHadLocalCopyFalseIsAddedHasLocalCopySetToTrue() { CreateAction(); var firstReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NewAssembly"); var secondReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NUnit.Framework"); packageManager.BeforeExecuteAction = () => { var referenceBeingRemoved = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NUnit.Framework"); referenceBeingRemoved.LocalCopy = false; packageManagementEvents.OnReferenceRemoving(referenceBeingRemoved); packageManagementEvents.OnReferenceAdding(firstReferenceBeingAdded); packageManagementEvents.OnReferenceAdding(secondReferenceBeingAdded); }; action.PreserveLocalCopyReferences = false; action.Execute(); Assert.IsTrue(firstReferenceBeingAdded.LocalCopy); Assert.IsTrue(secondReferenceBeingAdded.LocalCopy); }
public void Execute_ReferenceBeingUpdatedHasLocalCopyTrueButCaseIsDifferent_ReferenceAddedHasLocalCopyTrue() { CreateAction(); AddInstallPackageIntoProjectAction("Test", "1.2"); var firstReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NewAssembly"); var secondReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NUnit.Framework"); packageManager.BeforeExecuteAction = () => { var referenceBeingRemoved = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "nunit.framework"); referenceBeingRemoved.LocalCopy = true; packageManagementEvents.OnReferenceRemoving(referenceBeingRemoved); packageManagementEvents.OnReferenceAdding(firstReferenceBeingAdded); packageManagementEvents.OnReferenceAdding(secondReferenceBeingAdded); }; action.Execute(); Assert.IsTrue(firstReferenceBeingAdded.LocalCopy); Assert.IsTrue(secondReferenceBeingAdded.LocalCopy); }
public void Execute_ReferenceBeingUpdatedHasLocalCopyTrueButCaseIsDifferent_ReferenceAddedHasLocalCopyTrue() { CreateSolution(); fakeProject.FakePackages.Add(new FakePackage("Test", "1.0")); action.Package = new FakePackage("Test", "1.1"); var firstReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NewAssembly"); var secondReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NUnit.Framework"); fakeProject.UpdatePackageAction = (p, a) => { var referenceBeingRemoved = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "nunit.framework"); referenceBeingRemoved.LocalCopy = true; packageManagementEvents.OnReferenceRemoving(referenceBeingRemoved); packageManagementEvents.OnReferenceAdding(firstReferenceBeingAdded); packageManagementEvents.OnReferenceAdding(secondReferenceBeingAdded); }; action.Execute(); Assert.IsTrue(firstReferenceBeingAdded.LocalCopy); Assert.IsTrue(secondReferenceBeingAdded.LocalCopy); }
public void Execute_PackageAlreadyExistsWhenInstallingItAgainAndReferenceBeingInstalledOriginallyHadLocalCopyFalse_ReferenceAddedHasLocalCopyFalse() { CreateAction(); action.PreserveLocalCopyReferences = true; var firstReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NewAssembly"); var secondReferenceBeingAdded = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NUnit.Framework"); packageManager.BeforeExecuteAction = () => { var referenceBeingRemoved = ProjectReference.CreateCustomReference(ReferenceType.Assembly, "NUnit.Framework"); referenceBeingRemoved.LocalCopy = false; packageManagementEvents.OnReferenceRemoving(referenceBeingRemoved); packageManagementEvents.OnReferenceAdding(firstReferenceBeingAdded); packageManagementEvents.OnReferenceAdding(secondReferenceBeingAdded); }; action.Execute(); Assert.IsTrue(firstReferenceBeingAdded.LocalCopy); Assert.IsFalse(secondReferenceBeingAdded.LocalCopy); Assert.IsTrue(action.PreserveLocalCopyReferences); }
public async Task TestWorkspaceFilesCacheUpdated_ProjectReferencedAdded() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); await IdeServices.Workspace.OpenWorkspaceItem(solFile); await IdeServices.TypeSystemService.ProcessPendingLoadOperations(); var sol = IdeServices.Workspace.GetAllItems <Solution> ().First(); IdeServices.Workspace.ActiveConfigurationId = sol.DefaultConfigurationId; var p = sol.FindProjectByName("ConsoleProject") as DotNetProject; var cacheDirectory = sol.GetPreferencesDirectory().Combine("project-cache"); var projectCacheFile = GetProjectCacheFile(cacheDirectory, p, "Debug"); Assert.IsTrue(File.Exists(projectCacheFile)); var cacheInfo = GetProjectCacheInfo(sol, p); Assert.IsNotNull(cacheInfo); Assert.IsFalse(p.References.Any(r => StringComparer.OrdinalIgnoreCase.Equals(r.Include, "System.Net.Http"))); var systemNetHttpReference = ProjectReference.CreateCustomReference(ReferenceType.Package, "System.Net.Http"); p.References.Add(systemNetHttpReference); await p.SaveAsync(Util.GetMonitor()); // Check for updated cache file. var updatedCacheInfo = await WaitForProjectInfoCacheToChange(sol, p, cacheInfo); // Check cached references. var matchedReference = updatedCacheInfo.References.FirstOrDefault(r => r.FilePath.FileNameWithoutExtension == systemNetHttpReference.Include); Assert.IsNotNull(matchedReference, "System.Net.Http reference not found"); }
public static void AddReference(FakeDotNetProject project, string referenceName, string hintPath = null) { var reference = ProjectReference.CreateCustomReference(ReferenceType.Assembly, referenceName, hintPath); project.References.Add(reference); }
void AddAssemblyReference(string fileName) { var projectItem = ProjectReference.CreateCustomReference(ReferenceType.Assembly, fileName); References.Add(projectItem); }
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); }