示例#1
0
        public static NUnitVersion?GetNUnitVersion(ProjectReference p)
        {
            if (p.Reference.IndexOf("GuiUnit", StringComparison.OrdinalIgnoreCase) != -1 || p.Reference.StartsWith("nunitlite", StringComparison.OrdinalIgnoreCase))
            {
                return(NUnitVersion.NUnit2);
            }
            if (p.Reference.IndexOf("nunit.framework", StringComparison.OrdinalIgnoreCase) != -1)
            {
                var selector = p.Project?.DefaultConfiguration.Selector;
                if (selector == null)
                {
                    return(NUnitVersion.Unknown);
                }

                var f = p.GetReferencedFileNames(selector).FirstOrDefault();
                if (f != null && File.Exists(f))
                {
                    try {
                        var aname = new AssemblyName(SystemAssemblyService.GetAssemblyName(f));
                        if (aname.Version.Major == 2)
                        {
                            return(NUnitVersion.NUnit2);
                        }
                        else
                        {
                            return(NUnitVersion.NUnit3);
                        }
                    } catch (Exception ex) {
                        LoggingService.LogError("Could not get assembly version", ex);
                    }
                }
            }
            return(null);
        }
示例#2
0
        public async Task RemoveRefreshedReferenceSaveProjectAndAddReferenceBackAgain()
        {
            string solFile = Util.GetSampleProject("reference-refresh", "ConsoleProject.sln");

            Solution sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            DotNetProject project = sol.GetAllItems <DotNetProject> ().FirstOrDefault();

            File.Move(project.BaseDirectory.Combine("test.dll"), project.BaseDirectory.Combine("test.dll.tmp"));

            sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            project = sol.GetAllItems <DotNetProject> ().FirstOrDefault();

            ProjectReference r = project.References.FirstOrDefault(re => re.Reference == "test");

            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsFalse(r.IsValid);

            File.Move(project.BaseDirectory.Combine("test.dll.tmp"), project.BaseDirectory.Combine("test.dll"));

            ProjectReference refreshedReference = r.GetRefreshedReference();

            Assert.IsNotNull(refreshedReference);

            project.References.Remove(r);
            await project.SaveAsync(Util.GetMonitor());

            project.References.Add(refreshedReference);
            await project.SaveAsync(Util.GetMonitor());

            // Reload project.
            sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            project = sol.GetAllItems <DotNetProject> ().FirstOrDefault();

            r = project.References.FirstOrDefault(re => re.Reference == "test");
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Assembly);
            Assert.AreEqual(r.GetReferencedFileNames(project.DefaultConfiguration.Selector).Single(), project.BaseDirectory.Combine("test.dll").FullPath.ToString());
            Assert.IsTrue(r.IsValid);

            sol.Dispose();
        }
示例#3
0
		string ProjectRefToString (ProjectReference pr, MakefileVar refVar)
		{
			string [] tmp = pr.GetReferencedFileNames (ConfigurationSelector.Default);
			if (tmp == null || tmp.Length == 0)
				//Reference not found, ignoring
				return null;

			return AsmRefToString (tmp [0], refVar, true);
		}
示例#4
0
		string GacRefToString (ProjectReference pr, Dictionary<string, bool> hasAcSubstPackages, MakefileVar refVar)
		{
			//Gac ref can be a full name OR a path!
			//FIXME: Use GetReferencedFileName and GetPackageFromPath ?
			string fullname = pr.Reference;
			SystemPackage pkg = pr.Package;
			if (pkg == null) {
				//reference could be a path
				pkg = assemblyContext.GetPackageFromPath (Path.GetFullPath (pr.Reference));
				if (pkg != null) {
					//Path
					try {
						fullname = AssemblyName.GetAssemblyName (pr.Reference).FullName;
						//If this throws : Invalid assembly!
						//let it fall through and be emitted as a asm ref
					} catch (FileNotFoundException) {
						pkg = null;
					} catch (BadImageFormatException) {
						pkg = null;
					}
				}
			}

			if (pkg == null)
				return AsmRefToString (pr.GetReferencedFileNames (ConfigurationSelector.Default) [0], refVar, false);

			// Reference is from a package

			if (pkg.IsCorePackage)
				//pkg:mono, Eg. System, System.Data etc
				return fullname.Split (new char [] {','}, 2) [0];

			//Ref is from a non-core package
			string varname = null;
			if (UseAutotools)
				//Check whether ref'ed in configure.in
				varname = ConfiguredPackages.GetVarNameFromName (pkg.Name);
			
			if (varname == null) {
				//Package not referenced in configure.in
				//Or not a autotools based project,
				//so emit -pkg:

				if (!hasAcSubstPackages.ContainsKey (pkg.Name)) {
					if (UseAutotools) {
						//Warn only if UseAutotools
						string msg = GettextCatalog.GetString (
							"A reference to the pkg-config package '{0}' is being emitted to the Makefile, " +
							"because at least one assembly from the package is used in the project '{1}'. However, " +
							"this dependency is not specified in the configure.in file, so you might need to " +
							"add it to ensure that the project builds successfully on other systems.", pkg.Name, pr.OwnerProject.Name);
						LoggingService.LogWarning (msg);
						monitor.ReportWarning (msg);
					}

					hasAcSubstPackages [pkg.Name] = false;
				}
			} else {
				// If the package as AC_SUBST(FOO_LIBS) defined, then
				// emit FOO_LIBS, else emit -pkg:foo
				if (ConfiguredPackages.HasAcSubst (varname + "_LIBS")) {
					hasAcSubstPackages [varname] = true;
				} else {
					hasAcSubstPackages [pkg.Name] = false;
				}
			}

			return null;
		}
		public static NUnitVersion? GetNUnitVersion (ProjectReference p)
		{
			if (p.Reference.IndexOf ("GuiUnit", StringComparison.OrdinalIgnoreCase) != -1 || p.Reference.StartsWith ("nunitlite", StringComparison.OrdinalIgnoreCase))
				return NUnitVersion.NUnit2;
			if (p.Reference.IndexOf ("nunit.framework", StringComparison.OrdinalIgnoreCase) != -1) {
				var selector = p.Project?.DefaultConfiguration.Selector;
				if (selector == null)
					return NUnitVersion.Unknown;

				var f = p.GetReferencedFileNames (selector).FirstOrDefault ();
				if (f != null && File.Exists (f)) {
					try {
						var aname = new AssemblyName (SystemAssemblyService.GetAssemblyName (f));
						if (aname.Version.Major == 2)
							return NUnitVersion.NUnit2;
						else
							return NUnitVersion.NUnit3;
					} catch (Exception ex) {
						LoggingService.LogError ("Could not get assembly version", ex);
					}
				}
			}
			return null;
		}
示例#6
0
		static string GenerateReferenceStub (IProgressMonitor monitor, ConfigurationSelector configurationSelector, DotNetProjectConfiguration configuration, ProjectReference reference)
		{
			StringBuilder result = new StringBuilder ();
			foreach (string fileName in reference.GetReferencedFileNames (configurationSelector)) {
				string name = Path.GetFileNameWithoutExtension (Path.GetFileName (fileName));
				string outputName = Path.Combine (configuration.OutputDirectory, name + ".jar");
				if (!System.IO.File.Exists (outputName)) {
					monitor.Log.WriteLine (String.Format (GettextCatalog.GetString ("Generating {0} reference stub ..."), name));
					monitor.Log.WriteLine ("ikvmstub \"" + fileName + "\"");
					ProcessWrapper p = Runtime.ProcessService.StartProcess ("ikvmstub", "\"" + fileName + "\"", configuration.OutputDirectory, monitor.Log, monitor.Log, null);
					p.WaitForExit ();
					if (p.ExitCode != 0) {
						monitor.ReportError ("Stub generation failed.", null);
						if (File.Exists (outputName)) {
							try {
								File.Delete (outputName);
							} catch {
								// Ignore
							}
						}
					}
				}
				AppendClasspath (result, outputName);
			}
			return result.ToString ();
		}
		//HACK: we don't have the info to do this properly, really the package management addin should handle this
		static bool IsFromPackage (ProjectReference r)
		{
			if (r.ReferenceType != ReferenceType.Assembly) {
				return false;
			}
			var packagesDir = r.Project.ParentSolution.BaseDirectory.Combine ("packages");
			return r.GetReferencedFileNames(null).Any (f => ((FilePath)f).IsChildPathOf (packagesDir));
		}