public ProjectDescription GetDescription(NuGetFramework targetFramework, Project project, LockFileTargetLibrary targetLibrary) { // This never returns null var targetFrameworkInfo = project.GetTargetFramework(targetFramework); var dependencies = new List<LibraryRange>(targetFrameworkInfo.Dependencies); // Add all of the project's dependencies dependencies.AddRange(project.Dependencies); if (targetFramework != null && targetFramework.IsDesktop()) { dependencies.Add(new LibraryRange("mscorlib", LibraryType.ReferenceAssembly, LibraryDependencyType.Build)); dependencies.Add(new LibraryRange("System", LibraryType.ReferenceAssembly, LibraryDependencyType.Build)); if (targetFramework.Version >= new Version(3, 5)) { dependencies.Add(new LibraryRange("System.Core", LibraryType.ReferenceAssembly, LibraryDependencyType.Build)); if (targetFramework.Version >= new Version(4, 0)) { if (!dependencies.Any(dep => string.Equals(dep.Name, "Microsoft.CSharp", StringComparison.OrdinalIgnoreCase))) { dependencies.Add(new LibraryRange("Microsoft.CSharp", LibraryType.ReferenceAssembly, LibraryDependencyType.Build)); } } } } if (targetLibrary != null) { // The lock file entry might have a filtered set of dependencies var lockFileDependencies = targetLibrary.Dependencies.ToDictionary(d => d.Id); // Remove all non-framework dependencies that don't appear in the lock file entry dependencies.RemoveAll(m => !lockFileDependencies.ContainsKey(m.Name) && m.Target != LibraryType.ReferenceAssembly); } // Mark the library as unresolved if there were specified frameworks // and none of them resolved bool unresolved = targetFrameworkInfo.FrameworkName == null; return new ProjectDescription( new LibraryRange(project.Name, LibraryType.Unspecified), project, dependencies, targetFrameworkInfo, !unresolved); }
public CompilationOutputFiles( string basePath, Project project, string configuration, NuGetFramework framework) { BasePath = basePath; Project = project; Configuration = configuration; Framework = framework; OutputExtension = FileNameSuffixes.DotNet.DynamicLib; var compilationOptions = Project.GetCompilerOptions(framework, configuration); if (framework.IsDesktop() && compilationOptions.EmitEntryPoint.GetValueOrDefault()) { OutputExtension = FileNameSuffixes.DotNet.Exe; } }
public ProjectDescription GetDescription(NuGetFramework targetFramework, Project project) { // This never returns null var targetFrameworkInfo = project.GetTargetFramework(targetFramework); var targetFrameworkDependencies = new List<LibraryRange>(targetFrameworkInfo.Dependencies); if (targetFramework != null && targetFramework.IsDesktop()) { targetFrameworkDependencies.Add(new LibraryRange("mscorlib", LibraryType.ReferenceAssembly, LibraryDependencyType.Build)); targetFrameworkDependencies.Add(new LibraryRange("System", LibraryType.ReferenceAssembly, LibraryDependencyType.Build)); if (targetFramework.Version >= new Version(3, 5)) { targetFrameworkDependencies.Add(new LibraryRange("System.Core", LibraryType.ReferenceAssembly, LibraryDependencyType.Build)); if (targetFramework.Version >= new Version(4, 0)) { targetFrameworkDependencies.Add(new LibraryRange("Microsoft.CSharp", LibraryType.ReferenceAssembly, LibraryDependencyType.Build)); } } } var dependencies = project.Dependencies.Concat(targetFrameworkDependencies).ToList(); // Mark the library as unresolved if there were specified frameworks // and none of them resolved bool unresolved = targetFrameworkInfo.FrameworkName == null; return new ProjectDescription( new LibraryRange(project.Name, LibraryType.Unspecified), project, dependencies, targetFrameworkInfo, !unresolved); }
private static CompilationSettings ToCompilationSettings(CommonCompilerOptions compilerOptions, NuGetFramework targetFramework, string projectDirectory) { var options = GetCompilationOptions(compilerOptions, projectDirectory); // Disable 1702 until roslyn turns this off by default options = options.WithSpecificDiagnosticOptions(new Dictionary<string, ReportDiagnostic> { { "CS1701", ReportDiagnostic.Suppress }, // Binding redirects { "CS1702", ReportDiagnostic.Suppress }, { "CS1705", ReportDiagnostic.Suppress } }); AssemblyIdentityComparer assemblyIdentityComparer = targetFramework.IsDesktop() ? DesktopAssemblyIdentityComparer.Default : null; options = options.WithAssemblyIdentityComparer(assemblyIdentityComparer); LanguageVersion languageVersion; if (!Enum.TryParse<LanguageVersion>(value: compilerOptions.LanguageVersion, ignoreCase: true, result: out languageVersion)) { languageVersion = LanguageVersion.CSharp6; } var settings = new CompilationSettings { LanguageVersion = languageVersion, Defines = compilerOptions.Defines ?? Enumerable.Empty<string>(), CompilationOptions = options }; return settings; }
private static CompilationSettings ToCompilationSettings(CommonCompilerOptions compilerOptions, NuGetFramework targetFramework, string projectDirectory) { var options = GetCompilationOptions(compilerOptions, projectDirectory); options = options.WithSpecificDiagnosticOptions(compilerOptions.SuppressWarnings.ToDictionary( suppress => suppress, _ => ReportDiagnostic.Suppress)); AssemblyIdentityComparer assemblyIdentityComparer = targetFramework.IsDesktop() ? DesktopAssemblyIdentityComparer.Default : null; options = options.WithAssemblyIdentityComparer(assemblyIdentityComparer); LanguageVersion languageVersion; if (!Enum.TryParse<LanguageVersion>(value: compilerOptions.LanguageVersion, ignoreCase: true, result: out languageVersion)) { languageVersion = LanguageVersion.CSharp6; } var settings = new CompilationSettings { LanguageVersion = languageVersion, Defines = compilerOptions.Defines ?? Enumerable.Empty<string>(), CompilationOptions = options }; return settings; }
private static string GetProjectOutput(Project project, NuGetFramework framework, string configuration, string outputPath) { var compilationOptions = project.GetCompilerOptions(framework, configuration); var outputExtension = ".dll"; if (framework.IsDesktop() && compilationOptions.EmitEntryPoint.GetValueOrDefault()) { outputExtension = ".exe"; } return Path.Combine(outputPath, project.Name + outputExtension); }
private static Library GetLibrary(LibraryExport export, NuGetFramework target, string configuration, bool runtime, IDictionary<string, Dependency> dependencyLookup) { var type = export.Library.Identity.Type.Value.ToLowerInvariant(); var serviceable = (export.Library as PackageDescription)?.Library.IsServiceable ?? false; var libraryDependencies = new List<Dependency>(); var libraryAssets = runtime ? export.RuntimeAssemblies : export.CompilationAssemblies; foreach (var libraryDependency in export.Library.Dependencies) { Dependency dependency; if (dependencyLookup.TryGetValue(libraryDependency.Name, out dependency)) { libraryDependencies.Add(dependency); } } string[] assemblies; if (type == "project") { var isExe = ((ProjectDescription) export.Library) .Project .GetCompilerOptions(target, configuration) .EmitEntryPoint .GetValueOrDefault(false); isExe &= target.IsDesktop(); assemblies = new[] { export.Library.Identity.Name + (isExe ? ".exe": ".dll") }; } else { assemblies = libraryAssets.Select(libraryAsset => libraryAsset.RelativePath).ToArray(); } if (runtime) { return new RuntimeLibrary( type, export.Library.Identity.Name, export.Library.Identity.Version.ToString(), export.Library.Hash, assemblies, libraryDependencies.ToArray(), serviceable ); } else { return new CompilationLibrary( type, export.Library.Identity.Name, export.Library.Identity.Version.ToString(), export.Library.Hash, assemblies, libraryDependencies.ToArray(), serviceable ); } }
private static FrameworkInformation GetFrameworkInformation(NuGetFramework targetFramework, string referenceAssembliesPath) { // Check for legacy frameworks if (targetFramework.IsDesktop() && targetFramework.Version <= new Version(3, 5)) { return GetLegacyFrameworkInformation(targetFramework, referenceAssembliesPath); } var basePath = Path.Combine(referenceAssembliesPath, targetFramework.Framework, "v" + GetDisplayVersion(targetFramework)); if (!string.IsNullOrEmpty(targetFramework.Profile)) { basePath = Path.Combine(basePath, "Profile", targetFramework.Profile); } var version = new DirectoryInfo(basePath); if (!version.Exists) { return null; } return GetFrameworkInformation(version, targetFramework); }
private string GetProjectOutputName(NuGetFramework framework) { var compilationOptions = Project.GetCompilerOptions(framework, Configuration); var outputExtension = ".dll"; if (framework.IsDesktop() && compilationOptions.EmitEntryPoint.GetValueOrDefault()) { outputExtension = ".exe"; } return Project.Name + outputExtension; }
private static IList<LibraryDependency> GetDependencies(NuGetFramework targetFramework, PackageDependencyGroup dependencies, FrameworkSpecificGroup frameworkAssemblies) { var libraryDependencies = new List<LibraryDependency>(); if (dependencies != null) { foreach (var d in dependencies.Packages) { libraryDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange { Name = d.Id, VersionRange = d.VersionRange } }); } } if (frameworkAssemblies == null) { return libraryDependencies; } if (!targetFramework.IsDesktop()) { // REVIEW: This isn't 100% correct since none *can* mean // any in theory, but in practice it means .NET full reference assembly // If there's no supported target frameworks and we're not targeting // the desktop framework then skip it. // To do this properly we'll need all reference assemblies supported // by each supported target framework which isn't always available. return libraryDependencies; } foreach (var name in frameworkAssemblies.Items) { libraryDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange { Name = name, TypeConstraint = LibraryTypes.Reference } }); } return libraryDependencies; }
public Library GetLibrary(LibraryRange libraryRange, NuGetFramework targetFramework) { var name = libraryRange.Name; PackageSpec packageSpec; // Can't find a project file with the name so bail if (!_resolver.TryResolvePackageSpec(name, out packageSpec)) { return null; } // This never returns null var targetFrameworkInfo = packageSpec.GetTargetFramework(targetFramework); var targetFrameworkDependencies = targetFrameworkInfo.Dependencies; if (targetFramework.IsDesktop()) { targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange { Name = "mscorlib", TypeConstraint = LibraryTypes.Reference } }); targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange { Name = "System", TypeConstraint = LibraryTypes.Reference } }); targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange { Name = "System.Core", TypeConstraint = LibraryTypes.Reference } }); targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange { Name = "Microsoft.CSharp", TypeConstraint = LibraryTypes.Reference } }); } var dependencies = packageSpec.Dependencies.Concat(targetFrameworkDependencies).ToList(); if (string.Equals(_projectReference?.Name, libraryRange.Name, StringComparison.OrdinalIgnoreCase)) { dependencies.AddRange(_projectReference.ExternalProjectReferences .Select(reference => new LibraryDependency { LibraryRange = new LibraryRange { Name = reference, VersionRange = VersionRange.All, TypeConstraint = LibraryTypes.ExternalProject } })); } // Mark the library as unresolved if there were specified frameworks // and none of them resolved var unresolved = targetFrameworkInfo.FrameworkName == null && packageSpec.TargetFrameworks.Any(); var library = new Library { LibraryRange = libraryRange, Identity = new LibraryIdentity { Name = packageSpec.Name, Version = packageSpec.Version, Type = LibraryTypes.Project, }, Path = packageSpec.FilePath, Dependencies = dependencies, Resolved = !unresolved, [KnownLibraryProperties.PackageSpec] = packageSpec }; return library; }
private ICommandResolver GetProjectDependenciesCommandResolver(NuGetFramework framework) { var environment = new EnvironmentProvider(); if (framework.IsDesktop()) { IPlatformCommandSpecFactory platformCommandSpecFactory = null; if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); } else { platformCommandSpecFactory = new GenericPlatformCommandSpecFactory(); } return new OutputPathCommandResolver(environment, platformCommandSpecFactory); } else { var packagedCommandSpecFactory = new PackagedCommandSpecFactory(); return new ProjectDependenciesCommandResolver(environment, packagedCommandSpecFactory); } }