// Internal for testing
        internal static bool IsMvcAssembly(AssemblyReference reference)
        {
            var fileName = reference?.FilePath.FileName;

            if (string.IsNullOrEmpty(fileName))
            {
                return(false);
            }

            if (string.Equals(reference.FilePath.FileName, MvcAssemblyFileName, StringComparison.OrdinalIgnoreCase))
            {
                // Mvc assembly
                return(true);
            }

            return(false);
        }
示例#2
0
		internal protected virtual async Task<List<AssemblyReference>> OnGetReferencedAssemblies (ConfigurationSelector configuration)
		{
			List<AssemblyReference> result = new List<AssemblyReference> ();
			if (CheckUseMSBuildEngine (configuration)) {
				// Get the references list from the msbuild project
				RemoteProjectBuilder builder = await GetProjectBuilder ();
				try {
					var configs = GetConfigurations (configuration, false);

					AssemblyReference [] refs;
					using (Counters.ResolveMSBuildReferencesTimer.BeginTiming (GetProjectEventMetadata (configuration)))
						refs = await builder.ResolveAssemblyReferences (configs, CancellationToken.None);
					foreach (var r in refs)
						result.Add (r);
				} finally {
					builder.ReleaseReference ();
				}
			} else {
				foreach (ProjectReference pref in References) {
					if (pref.ReferenceType != ReferenceType.Project) {
						foreach (string asm in pref.GetReferencedFileNames (configuration))
							result.Add (new AssemblyReference (asm, pref.Aliases));
					}
				}
				var mscorlib = AssemblyContext.GetAssemblyFullName ("mscorlib", TargetFramework);
				var mscorlibPath = AssemblyContext.GetAssemblyLocation (mscorlib, TargetFramework);
				if (!result.Any (ar => ar.FilePath == mscorlibPath))
					result.Add (new AssemblyReference (mscorlibPath));

				var core = AssemblyContext.GetAssemblyFullName ("System.Core", TargetFramework);
				var corePath = AssemblyContext.GetAssemblyLocation (core, TargetFramework);
				if (!string.IsNullOrEmpty (corePath)) {
					if (!result.Any (ar => ar.FilePath == corePath))
						result.Add (new AssemblyReference (corePath));
				}
			}

			var config = (DotNetProjectConfiguration)GetConfiguration (configuration);
			bool noStdLib = false;
			if (config != null)
				noStdLib = config.CompilationParameters.NoStdLib;

			// System.Core is an implicit reference
			if (!noStdLib) {
				var sa = AssemblyContext.GetAssemblies (TargetFramework).FirstOrDefault (a => a.Name == "System.Core" && a.Package.IsFrameworkPackage);
				if (sa != null) {
					var ar = new AssemblyReference (sa.Location);
					if (!result.Contains (ar))
						result.Add (ar);
				}
			}
			var addFacadeAssemblies = false;
			foreach (var r in GetReferencedAssemblyProjects (configuration)) {
				if (r.IsPortableLibrary) {
					addFacadeAssemblies = true;
					break;
				}
			}
			if (!addFacadeAssemblies) {
				foreach (var refFilename in result) {
					string fullPath = null;
					if (!Path.IsPathRooted (refFilename.FilePath)) {
						fullPath = Path.Combine (Path.GetDirectoryName (FileName), refFilename.FilePath);
					} else {
						fullPath = Path.GetFullPath (refFilename.FilePath);
					}
					if (SystemAssemblyService.ContainsReferenceToSystemRuntime (fullPath)) {
						addFacadeAssemblies = true;
						break;
					}
				}
			}

			if (addFacadeAssemblies) {
				var runtime = TargetRuntime ?? MonoDevelop.Core.Runtime.SystemAssemblyService.DefaultRuntime;
				var facades = runtime.FindFacadeAssembliesForPCL (TargetFramework);
				foreach (var facade in facades) {
					if (!File.Exists (facade))
						continue;
					var ar = new AssemblyReference (facade);
					if (!result.Contains (ar))
						result.Add (ar);
				}
			}
			return result;
		}