public override IEnumerable <FrameworkName> GetSupportedFrameworks() { IEnumerable <FrameworkName> fileFrameworks; #if LOADER using (Stream stream = _streamFactory()) { var package = new ZipArchive(stream); string effectivePath; fileFrameworks = from part in package.Entries let path = part.FullName.Replace('/', '\\') where IsPackageFile(part) select VersionUtility.ParseFrameworkNameFromFilePath(path, out effectivePath); } #else IEnumerable <IPackageFile> cachedFiles; if (_enableCaching && MemoryCache.Instance.TryGetValue(GetFilesCacheKey(), out cachedFiles)) { fileFrameworks = cachedFiles.Select(c => c.TargetFramework); } else { using (Stream stream = _streamFactory()) { var package = Package.Open(stream); string effectivePath; fileFrameworks = from part in package.GetParts() where IsPackageFile(part) select VersionUtility.ParseFrameworkNameFromFilePath(UriUtility.GetPath(part.Uri), out effectivePath); } } #endif return(base.GetSupportedFrameworks() .Concat(fileFrameworks) .Where(f => f != null) .Distinct()); }
/// <summary> /// Attempt to parse a profile string into an instance of <see cref="NetPortableProfile"/>. /// The profile string can be either ProfileXXX or sl4+net45+wp7 /// </summary> public static NetPortableProfile Parse(NetPortableProfileTable table, string profileValue, bool treatOptionalFrameworksAsSupportedFrameworks = false) { if (String.IsNullOrEmpty(profileValue)) { throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "profileValue"); } // Previously, only the full "ProfileXXX" long .NET name could be used for this method. // This was inconsistent with the way the "custom profile string" (like "sl4+net45+wp7") // was supported in other places. By fixing the way the profile table indexes the cached // profiles, we can now indeed access by either naming, so we don't need the old check // for the string starting with "Profile". var result = table.GetProfile(profileValue); if (result != null) { if (treatOptionalFrameworksAsSupportedFrameworks) { result = new NetPortableProfile(result.Name, result.SupportedFrameworks.Concat(result.OptionalFrameworks)); } return(result); } if (profileValue.StartsWith(ProfilePrefix, StringComparison.OrdinalIgnoreCase)) { // This can happen if profileValue is an unrecognized profile, or // for some rare cases, the Portable Profile files are missing on disk. return(null); } VersionUtility.ValidatePortableFrameworkProfilePart(profileValue); var supportedFrameworks = profileValue.Split(new [] { '+' }, StringSplitOptions.RemoveEmptyEntries) .Select(VersionUtility.ParseFrameworkName); return(new NetPortableProfile(profileValue, supportedFrameworks)); }
public static FrameworkName ParseFrameworkNameFromFilePath(string filePath, out string effectivePath) { var knownFolders = new string[] { Constants.ContentDirectory, Constants.LibDirectory, Constants.ToolsDirectory, Constants.BuildDirectory }; for (int i = 0; i < knownFolders.Length; i++) { string folderPrefix = knownFolders[i] + System.IO.Path.DirectorySeparatorChar; if (filePath.Length > folderPrefix.Length && filePath.StartsWith(folderPrefix, StringComparison.OrdinalIgnoreCase)) { string frameworkPart = filePath.Substring(folderPrefix.Length); try { return(VersionUtility.ParseFrameworkFolderName( frameworkPart, strictParsing: knownFolders[i] == Constants.LibDirectory, effectivePath: out effectivePath)); } catch (ArgumentException) { // if the parsing fails, we treat it as if this file // doesn't have target framework. effectivePath = frameworkPart; return(null); } } } effectivePath = filePath; return(null); }
private void AddUpdateOperations(string id, SemanticVersion version, IEnumerable <IProjectManager> projectManagers) { if (!this.Safe) { foreach (IProjectManager manager in projectManagers) { this.AddUnsafeUpdateOperation(id, version, version != null, manager); } } else { foreach (IProjectManager manager2 in projectManagers) { IPackage package = manager2.LocalRepository.FindPackage(id); if (package != null) { IVersionSpec safeRange = VersionUtility.GetSafeRange(package.Version); IPackage package2 = manager2.PackageManager.SourceRepository.FindPackage(id, safeRange, manager2.ConstraintProvider, this.AllowPrereleaseVersions, false); this.Resolver.AddOperation(PackageAction.Install, package2, manager2); } } } }
private void AddEntry(XDocument document, string id, SemanticVersion version, bool developmentDependency, FrameworkName targetFramework, bool requireReinstallation) { string str; string str2; XElement element = FindEntry(document, id, version); if (element != null) { element.Remove(); } object[] content = new object[] { new XAttribute("id", id), new XAttribute("version", version) }; XElement element2 = new XElement("package", content); if (targetFramework != null) { element2.Add(new XAttribute("targetFramework", VersionUtility.GetShortFrameworkName(targetFramework))); } if (this._constraints.TryGetValue(id, out str)) { element2.Add(new XAttribute("allowedVersions", str)); } if (this._developmentFlags.TryGetValue(id, out str2)) { element2.Add(new XAttribute("developmentDependency", str2)); } else if (developmentDependency) { element2.Add(new XAttribute("developmentDependency", "true")); } if (requireReinstallation) { element2.Add(new XAttribute("requireReinstallation", bool.TrueString)); } document.Root.Add(element2); this.SaveDocument(document); }
private void UpdatePackageReference(string packageId, Func <IPackage> resolvePackage, bool updateDependencies, bool allowPrereleaseVersions, bool targetVersionSetExplicitly) { if (String.IsNullOrEmpty(packageId)) { throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "packageId"); } IPackage oldPackage = LocalRepository.FindPackage(packageId); // Check to see if this package is installed if (oldPackage == null) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, NuGetResources.ProjectDoesNotHaveReference, Project.ProjectName, packageId)); } Logger.Log(MessageLevel.Debug, NuGetResources.Debug_LookingForUpdates, packageId); IPackage package = resolvePackage(); // the condition (allowPrereleaseVersions || targetVersionSetExplicitly || oldPackage.IsReleaseVersion() || !package.IsReleaseVersion() || oldPackage.Version < package.Version) // is to fix bug 1574. We want to do nothing if, let's say, you have package 2.0alpha installed, and you do: // update-package // without specifying a version explicitly, and the feed only has version 1.0 as the latest stable version. if (package != null && oldPackage.Version != package.Version && (allowPrereleaseVersions || targetVersionSetExplicitly || oldPackage.IsReleaseVersion() || !package.IsReleaseVersion() || oldPackage.Version < package.Version)) { Logger.Log(MessageLevel.Info, NuGetResources.Log_UpdatingPackages, package.Id, oldPackage.Version, package.Version, Project.ProjectName); UpdatePackageReference(package, updateDependencies, allowPrereleaseVersions); } else { IVersionSpec constraint = ConstraintProvider.GetConstraint(packageId); if (constraint != null) { Logger.Log(MessageLevel.Info, NuGetResources.Log_ApplyingConstraints, packageId, VersionUtility.PrettyPrint(constraint), ConstraintProvider.Source); } Logger.Log(MessageLevel.Info, NuGetResources.Log_NoUpdatesAvailableForProject, packageId, Project.ProjectName); } }
protected virtual void ExtractPackageFilesToProject(IPackage package) { // BUG 491: Installing a package with incompatible binaries still does a partial install. // Resolve assembly references and content files first so that if this fails we never do anything to the project IList <IPackageAssemblyReference> assemblyReferences = Project.GetCompatibleItemsCore(package.AssemblyReferences).ToList(); IList <FrameworkAssemblyReference> frameworkReferences = Project.GetCompatibleItemsCore(package.FrameworkAssemblies).ToList(); IList <IPackageFile> contentFiles = Project.GetCompatibleItemsCore(package.GetContentFiles()).ToList(); // If the package doesn't have any compatible assembly references or content files, // throw, unless it's a meta package. if (assemblyReferences.Count == 0 && frameworkReferences.Count == 0 && contentFiles.Count == 0 && (package.FrameworkAssemblies.Any() || package.AssemblyReferences.Any() || package.GetContentFiles().Any())) { // for portable framework, we want to show the friendly short form (e.g. portable-win8+net45+wp8) instead of ".NETPortable, Profile=Profile104". string targetFrameworkString = VersionUtility.IsPortableFramework(Project.TargetFramework) ? VersionUtility.GetShortFrameworkName(Project.TargetFramework) : Project.TargetFramework.ToString(); throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, NuGetResources.UnableToFindCompatibleItems, package.GetFullName(), targetFrameworkString)); } try { // Add content files Project.AddFiles(contentFiles, _fileTransformers); // Add the references to the reference path foreach (IPackageAssemblyReference assemblyReference in assemblyReferences) { if (assemblyReference.IsEmptyFolder()) { continue; } // Get the physical path of the assembly reference string referencePath = Path.Combine(PathResolver.GetInstallPath(package), assemblyReference.Path); string relativeReferencePath = PathUtility.GetRelativePath(Project.Root, referencePath); if (Project.ReferenceExists(assemblyReference.Name)) { Project.RemoveReference(assemblyReference.Name); } // The current implementation of all ProjectSystem does not use the Stream parameter at all. // We can't change the API now, so just pass in a null stream. Project.AddReference(relativeReferencePath, Stream.Null); } // Add GAC/Framework references foreach (FrameworkAssemblyReference frameworkReference in frameworkReferences) { if (!Project.ReferenceExists(frameworkReference.AssemblyName)) { Project.AddFrameworkReference(frameworkReference.AssemblyName); } } } finally { if (_packageReferenceRepository != null) { // save the used project's framework if the repository supports it. _packageReferenceRepository.AddPackage(package.Id, package.Version, Project.TargetFramework); } else { // Add package to local repository in the finally so that the user can uninstall it // if any exception occurs. This is easier than rolling back since the user can just // manually uninstall things that may have failed. // If this fails then the user is out of luck. LocalRepository.AddPackage(package); } } }
public override string ToString() => ((this.VersionSpec != null) ? (this.Id + " " + VersionUtility.PrettyPrint(this.VersionSpec)) : this.Id);
private void LogTargetFrameworkInfo(IPackage package, List <IPackageAssemblyReference> assemblyReferences, List <IPackageFile> contentFiles, List <IPackageFile> buildFiles) { if ((assemblyReferences.Count > 0) || ((contentFiles.Count > 0) || (buildFiles.Count > 0))) { string str = (this.Project.TargetFramework == null) ? string.Empty : VersionUtility.GetShortFrameworkName(this.Project.TargetFramework); object[] args = new object[] { package.GetFullName(), this.Project.ProjectName, str }; this.Logger.Log(MessageLevel.Debug, NuGetResources.Debug_TargetFrameworkInfoPrefix, args); if (assemblyReferences.Count > 0) { object[] objArray2 = new object[] { NuGetResources.Debug_TargetFrameworkInfo_AssemblyReferences, Path.GetDirectoryName(assemblyReferences[0].Path), VersionUtility.GetTargetFrameworkLogString(assemblyReferences[0].TargetFramework) }; this.Logger.Log(MessageLevel.Debug, NuGetResources.Debug_TargetFrameworkInfo, objArray2); } if (contentFiles.Count > 0) { object[] objArray3 = new object[] { NuGetResources.Debug_TargetFrameworkInfo_ContentFiles, Path.GetDirectoryName(contentFiles[0].Path), VersionUtility.GetTargetFrameworkLogString(contentFiles[0].TargetFramework) }; this.Logger.Log(MessageLevel.Debug, NuGetResources.Debug_TargetFrameworkInfo, objArray3); } if (buildFiles.Count > 0) { object[] objArray4 = new object[] { NuGetResources.Debug_TargetFrameworkInfo_BuildFiles, Path.GetDirectoryName(buildFiles[0].Path), VersionUtility.GetTargetFrameworkLogString(buildFiles[0].TargetFramework) }; this.Logger.Log(MessageLevel.Debug, NuGetResources.Debug_TargetFrameworkInfo, objArray4); } } }
protected override void OnDependencyResolveError(PackageDependency dependency) { IVersionSpec spec = ConstraintProvider.GetConstraint(dependency.Id); string message = String.Empty; if (spec != null) { message = String.Format(CultureInfo.CurrentCulture, NuGetResources.AdditonalConstraintsDefined, dependency.Id, VersionUtility.PrettyPrint(spec), ConstraintProvider.Source); } throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, NuGetResources.UnableToResolveDependency + message, dependency)); }
protected virtual void ExtractPackageFilesToProject(IPackage package) { // BUG 491: Installing a package with incompatible binaries still does a partial install. // Resolve assembly references and content files first so that if this fails we never do anything to the project List <IPackageAssemblyReference> assemblyReferences = Project.GetCompatibleItemsCore(package.AssemblyReferences).ToList(); List <FrameworkAssemblyReference> frameworkReferences = Project.GetCompatibleItemsCore(package.FrameworkAssemblies).ToList(); List <IPackageFile> contentFiles = Project.GetCompatibleItemsCore(package.GetContentFiles()).ToList(); List <IPackageFile> buildFiles = Project.GetCompatibleItemsCore(package.GetBuildFiles()).ToList(); // If the package doesn't have any compatible assembly references or content files, // throw, unless it's a meta package. if (assemblyReferences.Count == 0 && frameworkReferences.Count == 0 && contentFiles.Count == 0 && buildFiles.Count == 0 && (package.FrameworkAssemblies.Any() || package.AssemblyReferences.Any() || package.GetContentFiles().Any() || package.GetBuildFiles().Any())) { // for portable framework, we want to show the friendly short form (e.g. portable-win8+net45+wp8) instead of ".NETPortable, Profile=Profile104". FrameworkName targetFramework = Project.TargetFramework; string targetFrameworkString = targetFramework.IsPortableFramework() ? VersionUtility.GetShortFrameworkName(targetFramework) : targetFramework != null?targetFramework.ToString() : null; throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, NuGetResources.UnableToFindCompatibleItems, package.GetFullName(), targetFrameworkString)); } // IMPORTANT: this filtering has to be done AFTER the 'if' statement above, // so that we don't throw the exception in case the <References> filters out all assemblies. FilterAssemblyReferences(assemblyReferences, package.PackageAssemblyReferences); try { // Log target framework info for debugging LogTargetFrameworkInfo(package, assemblyReferences, contentFiles, buildFiles); // Add content files Project.AddFiles(contentFiles, _fileTransformers); // Add the references to the reference path foreach (IPackageAssemblyReference assemblyReference in assemblyReferences) { if (assemblyReference.IsEmptyFolder()) { continue; } // Get the physical path of the assembly reference string referencePath = Path.Combine(PathResolver.GetInstallPath(package), assemblyReference.Path); string relativeReferencePath = PathUtility.GetRelativePath(Project.Root, referencePath); if (Project.ReferenceExists(assemblyReference.Name)) { Project.RemoveReference(assemblyReference.Name); } Project.AddReference(relativeReferencePath); } // Add GAC/Framework references foreach (FrameworkAssemblyReference frameworkReference in frameworkReferences) { if (!Project.ReferenceExists(frameworkReference.AssemblyName)) { Project.AddFrameworkReference(frameworkReference.AssemblyName); } } foreach (var importFile in buildFiles) { string fullImportFilePath = Path.Combine(PathResolver.GetInstallPath(package), importFile.Path); Project.AddImport( fullImportFilePath, importFile.Path.EndsWith(".props", StringComparison.OrdinalIgnoreCase) ? ProjectImportLocation.Top : ProjectImportLocation.Bottom); } } finally { if (_packageReferenceRepository != null) { // save the used project's framework if the repository supports it. _packageReferenceRepository.AddPackage(package.Id, package.Version, package.DevelopmentDependency, Project.TargetFramework); } else { // Add package to local repository in the finally so that the user can uninstall it // if any exception occurs. This is easier than rolling back since the user can just // manually uninstall things that may have failed. // If this fails then the user is out of luck. LocalRepository.AddPackage(package); } } }
private static Version GetEffectiveFrameworkVersion(FrameworkName projectFramework, FrameworkName targetFrameworkVersion) { if (targetFrameworkVersion.IsPortableFramework()) { NetPortableProfile profile = NetPortableProfile.Parse(targetFrameworkVersion.Profile); if (profile != null) { // if it's a portable library, return the version of the matching framework var compatibleFramework = profile.SupportedFrameworks.FirstOrDefault(f => VersionUtility.IsCompatible(projectFramework, f)); if (compatibleFramework != null) { return(compatibleFramework.Version); } } } return(targetFrameworkVersion.Version); }
public PackageDependencySet(string targetFramework, IEnumerable <PackageDependency> dependencies) : this(targetFramework != null ? VersionUtility.ParseFrameworkName(targetFramework) : null, dependencies) { }
public PackageDependency(string id, string version) : this(id, string.IsNullOrEmpty(version) ? null : VersionUtility.ParseVersionSpec(version)) { }
private static Tuple <string, IVersionSpec, FrameworkName> ParseDependency(string value) { if (string.IsNullOrWhiteSpace(value)) { return(null); } char[] separator = new char[] { ':' }; string[] strArray = value.Trim().Split(separator); if (strArray.Length == 0) { return(null); } IVersionSpec result = null; if (strArray.Length > 1) { VersionUtility.TryParseVersionSpec(strArray[1], out result); } return(Tuple.Create <string, IVersionSpec, FrameworkName>(strArray[0].Trim(), result, ((strArray.Length <= 2) || string.IsNullOrEmpty(strArray[2])) ? null : VersionUtility.ParseFrameworkName(strArray[2]))); }
public IEnumerable <PackageReference> GetPackageReferences(bool requireVersion) { XDocument document = GetDocument(); if (document == null) { yield break; } foreach (var e in document.Root.Elements("package")) { string id = e.GetOptionalAttributeValue("id"); string versionString = e.GetOptionalAttributeValue("version"); string versionConstraintString = e.GetOptionalAttributeValue("allowedVersions"); string targetFrameworkString = e.GetOptionalAttributeValue("targetFramework"); string developmentFlagString = e.GetOptionalAttributeValue("developmentDependency"); string requireReinstallationString = e.GetOptionalAttributeValue("requireReinstallation"); SemanticVersion version = null; if (String.IsNullOrEmpty(id)) { // If the id is empty, ignore the record continue; } // If the version is invalid, raise an error unless it's both empty and not required if ((requireVersion || !String.IsNullOrEmpty(versionString)) && !SemanticVersion.TryParse(versionString, out version)) { throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidVersion, versionString, _path)); } IVersionSpec versionConstaint = null; if (!String.IsNullOrEmpty(versionConstraintString)) { if (!VersionUtility.TryParseVersionSpec(versionConstraintString, out versionConstaint)) { throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidVersion, versionConstraintString, _path)); } _constraints[id] = versionConstraintString; } FrameworkName targetFramework = null; if (!String.IsNullOrEmpty(targetFrameworkString)) { targetFramework = VersionUtility.ParseFrameworkName(targetFrameworkString); if (targetFramework == VersionUtility.UnsupportedFrameworkName) { targetFramework = null; } } var developmentFlag = false; if (!String.IsNullOrEmpty(developmentFlagString)) { if (!Boolean.TryParse(developmentFlagString, out developmentFlag)) { throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidDevelopmentFlag, developmentFlagString, _path)); } _developmentFlags[id] = developmentFlagString; } var requireReinstallation = false; if (!String.IsNullOrEmpty(requireReinstallationString)) { if (!Boolean.TryParse(requireReinstallationString, out requireReinstallation)) { throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidRequireReinstallationFlag, requireReinstallationString, _path)); } } yield return(new PackageReference(id, version, versionConstaint, targetFramework, developmentFlag, requireReinstallation)); } }
internal static IEnumerable <T> GetCompatibleItemsCore <T>(this IProjectSystem projectSystem, IEnumerable <T> items) where T : IFrameworkTargetable { IEnumerable <T> enumerable; return(!VersionUtility.TryGetCompatibleItems <T>(projectSystem.TargetFramework, items, out enumerable) ? Enumerable.Empty <T>() : enumerable); }
private static bool SupportsTargetFrameworks(IEnumerable <FrameworkName> targetFramework, IPackage package) { return(targetFramework.IsEmpty() || targetFramework.Any(t => VersionUtility.IsCompatible(t, package.GetSupportedFrameworks()))); }
void AddUnsafeUpdateOperation( string id, SemanticVersion version, bool targetVersionSetExplicitly, IProjectManager projectManager) { Logger.Log(MessageLevel.Debug, NuGetResources.Debug_LookingForUpdates, id); var package = projectManager.PackageManager.SourceRepository.FindPackage( id, version, projectManager.ConstraintProvider, AllowPrereleaseVersions, allowUnlisted: false); if (package != null) { Logger.Log(MessageLevel.Info, NuGetResources.Log_UpdatingPackages, package.Id, package.Version, projectManager.Project.ProjectName); Resolver.AddOperation(PackageAction.Install, package, projectManager); } else { throw new Exception(String.Format(NuGetResources.InvalidVersionString, version.ToString())); } // Display message that no updates are available. IVersionSpec constraint = projectManager.ConstraintProvider.GetConstraint(package.Id); if (constraint != null) { Logger.Log(MessageLevel.Info, NuGetResources.Log_ApplyingConstraints, package.Id, VersionUtility.PrettyPrint(constraint), projectManager.ConstraintProvider.Source); } Logger.Log( MessageLevel.Info, NuGetResources.Log_NoUpdatesAvailableForProject, package.Id, projectManager.Project.ProjectName); }
internal static int GetCompatibilityBetweenPortableLibraryAndNonPortableLibrary(FrameworkName frameworkName, FrameworkName portableFramework) { NetPortableProfile profile = NetPortableProfile.Parse(portableFramework.Profile); if (profile == null) { // defensive coding, this should never happen Debug.Fail("'portableFramework' is not a valid portable framework."); return(0); } // among the supported frameworks by the Portable library, pick the one that is compatible with 'frameworkName' var compatibleFramework = profile.SupportedFrameworks.FirstOrDefault(f => VersionUtility.IsCompatible(frameworkName, f)); return(compatibleFramework == null ? 0 : GetProfileCompatibility(frameworkName, compatibleFramework)); }
internal static PackageDependency CreateDependency(string id, string versionSpec) { return(new PackageDependency(id, VersionUtility.ParseVersionSpec(versionSpec))); }
public bool IsCompatibleWith(FrameworkName projectFramework, NetPortableProfileTable portableProfileTable) { if (projectFramework == null) { throw new ArgumentNullException("projectFramework"); } return(Enumerable.Any <FrameworkName>(this.SupportedFrameworks, (Func <FrameworkName, bool>)(packageFramework => VersionUtility.IsCompatible(projectFramework, packageFramework, portableProfileTable))) || portableProfileTable.HasCompatibleProfileWith(this, projectFramework, portableProfileTable)); }
private void LogTargetFrameworkInfo(IPackage package, List <IPackageAssemblyReference> assemblyReferences, List <IPackageFile> contentFiles, List <IPackageFile> buildFiles) { if (assemblyReferences.Count > 0 || contentFiles.Count > 0 || buildFiles.Count > 0) { // targetFramework can be null for unknown project types string shortFramework = Project.TargetFramework == null ? string.Empty : VersionUtility.GetShortFrameworkName(Project.TargetFramework); Logger.Log(MessageLevel.Debug, NuGetResources.Debug_TargetFrameworkInfoPrefix, package.GetFullName(), Project.ProjectName, shortFramework); if (assemblyReferences.Count > 0) { Logger.Log(MessageLevel.Debug, NuGetResources.Debug_TargetFrameworkInfo, NuGetResources.Debug_TargetFrameworkInfo_AssemblyReferences, Path.GetDirectoryName(assemblyReferences[0].Path), VersionUtility.GetTargetFrameworkLogString(assemblyReferences[0].TargetFramework)); } if (contentFiles.Count > 0) { Logger.Log(MessageLevel.Debug, NuGetResources.Debug_TargetFrameworkInfo, NuGetResources.Debug_TargetFrameworkInfo_ContentFiles, Path.GetDirectoryName(contentFiles[0].Path), VersionUtility.GetTargetFrameworkLogString(contentFiles[0].TargetFramework)); } if (buildFiles.Count > 0) { Logger.Log(MessageLevel.Debug, NuGetResources.Debug_TargetFrameworkInfo, NuGetResources.Debug_TargetFrameworkInfo_BuildFiles, Path.GetDirectoryName(buildFiles[0].Path), VersionUtility.GetTargetFrameworkLogString(buildFiles[0].TargetFramework)); } } }
private static PackageDependencySet CreatePackageDependencySet(ManifestDependencySet manifestDependencySet) => new PackageDependencySet((manifestDependencySet.TargetFramework == null) ? null : VersionUtility.ParseFrameworkName(manifestDependencySet.TargetFramework), from d in manifestDependencySet.Dependencies select new PackageDependency(d.Id, string.IsNullOrEmpty(d.Version) ? null : VersionUtility.ParseVersionSpec(d.Version)));
void AddUnsafeUpdateOperation( string id, SemanticVersion version, bool targetVersionSetExplicitly, IProjectManager projectManager) { var oldPackage = projectManager.LocalRepository.FindPackage(id); if (oldPackage == null) { return; } Logger.Log(MessageLevel.Debug, NuGetResources.Debug_LookingForUpdates, id); var package = projectManager.PackageManager.SourceRepository.FindPackage( id, version, projectManager.ConstraintProvider, AllowPrereleaseVersions, allowUnlisted: false); // the condition (allowPrereleaseVersions || targetVersionSetExplicitly || oldPackage.IsReleaseVersion() || !package.IsReleaseVersion() || oldPackage.Version < package.Version) // is to fix bug 1574. We want to do nothing if, let's say, you have package 2.0alpha installed, and you do: // update-package // without specifying a version explicitly, and the feed only has version 1.0 as the latest stable version. if (package != null && oldPackage.Version != package.Version && (AllowPrereleaseVersions || targetVersionSetExplicitly || oldPackage.IsReleaseVersion() || !package.IsReleaseVersion() || oldPackage.Version < package.Version)) { Logger.Log(MessageLevel.Info, NuGetResources.Log_UpdatingPackages, package.Id, oldPackage.Version, package.Version, projectManager.Project.ProjectName); Resolver.AddOperation(PackageAction.Install, package, projectManager); } else { throw new Exception(String.Format(NuGetResources.InvalidVersionString, version.ToString())); } // Display message that no updates are available. IVersionSpec constraint = projectManager.ConstraintProvider.GetConstraint(package.Id); if (constraint != null) { Logger.Log(MessageLevel.Info, NuGetResources.Log_ApplyingConstraints, package.Id, VersionUtility.PrettyPrint(constraint), projectManager.ConstraintProvider.Source); } Logger.Log( MessageLevel.Info, NuGetResources.Log_NoUpdatesAvailableForProject, package.Id, projectManager.Project.ProjectName); }
protected virtual void ExtractPackageFilesToProject(IPackage package) { List <IPackageAssemblyReference> assemblyReferences = this.Project.GetCompatibleItemsCore <IPackageAssemblyReference>(package.AssemblyReferences).ToList <IPackageAssemblyReference>(); List <FrameworkAssemblyReference> list2 = this.Project.GetCompatibleItemsCore <FrameworkAssemblyReference>(package.FrameworkAssemblies).ToList <FrameworkAssemblyReference>(); List <IPackageFile> contentFiles = this.Project.GetCompatibleItemsCore <IPackageFile>(package.GetContentFiles()).ToList <IPackageFile>(); List <IPackageFile> buildFiles = this.Project.GetCompatibleItemsCore <IPackageFile>(package.GetBuildFiles()).ToList <IPackageFile>(); if ((assemblyReferences.Count == 0) && ((list2.Count == 0) && ((contentFiles.Count == 0) && ((buildFiles.Count == 0) && (package.FrameworkAssemblies.Any <FrameworkAssemblyReference>() || (package.AssemblyReferences.Any <IPackageAssemblyReference>() || (package.GetContentFiles().Any <IPackageFile>() || package.GetBuildFiles().Any <IPackageFile>()))))))) { FrameworkName targetFramework = this.Project.TargetFramework; string str = targetFramework.IsPortableFramework() ? VersionUtility.GetShortFrameworkName(targetFramework) : targetFramework?.ToString(); object[] args = new object[] { package.GetFullName(), str }; throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, NuGetResources.UnableToFindCompatibleItems, args)); } this.FilterAssemblyReferences(assemblyReferences, package.PackageAssemblyReferences); try { this.LogTargetFrameworkInfo(package, assemblyReferences, contentFiles, buildFiles); this.Project.AddFiles(contentFiles, this._fileTransformers); foreach (IPackageAssemblyReference reference in assemblyReferences) { if (!reference.IsEmptyFolder()) { string str2 = Path.Combine(this.PathResolver.GetInstallPath(package), reference.Path); string relativePath = PathUtility.GetRelativePath(this.Project.Root, str2); if (this.Project.ReferenceExists(reference.Name)) { this.Project.RemoveReference(reference.Name); } this.Project.AddReference(relativePath); } } foreach (FrameworkAssemblyReference reference2 in list2) { if (!this.Project.ReferenceExists(reference2.AssemblyName)) { this.Project.AddFrameworkReference(reference2.AssemblyName); } } foreach (IPackageFile file in buildFiles) { string targetFullPath = Path.Combine(this.PathResolver.GetInstallPath(package), file.Path); this.Project.AddImport(targetFullPath, file.Path.EndsWith(".props", StringComparison.OrdinalIgnoreCase) ? ProjectImportLocation.Top : ProjectImportLocation.Bottom); } } finally { if (this._packageReferenceRepository != null) { this._packageReferenceRepository.AddPackage(package.Id, package.Version, package.DevelopmentDependency, this.Project.TargetFramework); } else { this.LocalRepository.AddPackage(package); } } }