-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix https://github.com/NuGet/Home/issues/225 #20
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,33 +17,6 @@ | |
|
||
namespace NuGet.ProjectManagement | ||
{ | ||
internal class PackageItemComparer : IComparer<string> | ||
{ | ||
public int Compare(string x, string y) | ||
{ | ||
// BUG 636: We sort files so that they are added in the correct order | ||
// e.g aspx before aspx.cs | ||
|
||
if (x.Equals(y, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return 0; | ||
} | ||
|
||
// Add files that are prefixes of other files first | ||
if (x.StartsWith(y, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (y.StartsWith(x, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return 1; | ||
} | ||
|
||
return string.Compare(y, x, StringComparison.OrdinalIgnoreCase); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// This class represents a NuGetProject based on a .NET project. This also contains an instance of a | ||
/// FolderNuGetProject | ||
|
@@ -92,7 +65,9 @@ public class MSBuildNuGetProject : NuGetProject | |
{ new FileTransformExtensions(".install.xdt", ".uninstall.xdt"), new XdtTransformer() } | ||
}; | ||
|
||
public MSBuildNuGetProject(IMSBuildNuGetProjectSystem msbuildNuGetProjectSystem, string folderNuGetProjectPath, string packagesConfigFolderPath) | ||
public MSBuildNuGetProject(IMSBuildNuGetProjectSystem msbuildNuGetProjectSystem, | ||
string folderNuGetProjectPath, | ||
string packagesConfigFolderPath) | ||
{ | ||
if (msbuildNuGetProjectSystem == null) | ||
{ | ||
|
@@ -178,7 +153,7 @@ public override async Task<bool> InstallPackageAsync( | |
return false; | ||
} | ||
|
||
// Step-2: Create PackageReader using the PackageStream and obtain the various item groups | ||
// Step-2: Create PackageReader using the PackageStream and obtain the various item groups | ||
downloadResourceResult.PackageStream.Seek(0, SeekOrigin.Begin); | ||
var packageReader = downloadResourceResult.PackageReader; | ||
if (packageReader == null) | ||
|
@@ -279,7 +254,7 @@ public override async Task<bool> InstallPackageAsync( | |
} | ||
PackageEventsProvider.Instance.NotifyInstalling(packageEventArgs); | ||
|
||
// Step-6: Install package to FolderNuGetProject | ||
// Step-6: Install package to FolderNuGetProject | ||
await FolderNuGetProject.InstallPackageAsync(packageIdentity, downloadResourceResult, nuGetProjectContext, token); | ||
|
||
// Step-7: Raise PackageInstalled event | ||
|
@@ -303,10 +278,12 @@ public override async Task<bool> InstallPackageAsync( | |
{ | ||
var referenceItemFullPath = Path.Combine(packageInstallPath, referenceItem); | ||
var referenceName = Path.GetFileName(referenceItem); | ||
|
||
if (MSBuildNuGetProjectSystem.ReferenceExists(referenceName)) | ||
{ | ||
MSBuildNuGetProjectSystem.RemoveReference(referenceName); | ||
} | ||
|
||
MSBuildNuGetProjectSystem.AddReference(referenceItemFullPath); | ||
} | ||
} | ||
|
@@ -403,36 +380,57 @@ public override async Task<bool> UninstallPackageAsync(PackageIdentity packageId | |
} | ||
|
||
var packageTargetFramework = packageReference.TargetFramework ?? MSBuildNuGetProjectSystem.TargetFramework; | ||
var packageEventArgs = new PackageEventArgs(FolderNuGetProject, packageIdentity, FolderNuGetProject.GetInstalledPath(packageIdentity)); | ||
var packageEventArgs = new PackageEventArgs(FolderNuGetProject, | ||
packageIdentity, | ||
FolderNuGetProject.GetInstalledPath(packageIdentity)); | ||
|
||
if (PackageUninstalling != null) | ||
{ | ||
PackageUninstalling(this, packageEventArgs); | ||
} | ||
|
||
using (var packageStream = File.OpenRead(FolderNuGetProject.GetInstalledPackageFilePath(packageIdentity))) | ||
{ | ||
// Step-2: Create PackageReader using the PackageStream and obtain the various item groups | ||
// Get the package target framework instead of using project targetframework | ||
var zipArchive = new ZipArchive(packageStream); | ||
var packageReader = new PackageReader(zipArchive); | ||
|
||
// Step-2: Execute powershell script - uninstall.ps1 | ||
var toolItemGroups = packageReader.GetToolItems(); | ||
var compatibleToolItemsGroup = MSBuildNuGetProjectSystemUtility | ||
.GetMostCompatibleGroup(packageTargetFramework, toolItemGroups); | ||
|
||
if (MSBuildNuGetProjectSystemUtility.IsValid(compatibleToolItemsGroup)) | ||
{ | ||
var uninstallPS1RelativePath = compatibleToolItemsGroup.Items.FirstOrDefault( | ||
p => p.EndsWith(Path.DirectorySeparatorChar + PowerShellScripts.Uninstall, StringComparison.OrdinalIgnoreCase)); | ||
|
||
if (!string.IsNullOrEmpty(uninstallPS1RelativePath)) | ||
{ | ||
var packageInstallPath = FolderNuGetProject.GetInstalledPath(packageIdentity); | ||
await MSBuildNuGetProjectSystem.ExecuteScriptAsync(packageIdentity, packageInstallPath, uninstallPS1RelativePath, this, throwOnFailure: false); | ||
} | ||
} | ||
|
||
// Step-3: Obtain the various item groups | ||
// Get the package target framework instead of using project targetframework | ||
var referenceItemGroups = packageReader.GetReferenceItems(); | ||
var contentFileGroups = packageReader.GetContentItems(); | ||
var buildFileGroups = packageReader.GetBuildItems(); | ||
|
||
// Step-3: Get the most compatible items groups for all items groups | ||
// Step-4: Get the most compatible items groups for all items groups | ||
var compatibleReferenceItemsGroup = | ||
MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(packageTargetFramework, referenceItemGroups); | ||
|
||
var compatibleContentFilesGroup = | ||
MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(packageTargetFramework, contentFileGroups); | ||
|
||
var compatibleBuildFilesGroup = | ||
MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(packageTargetFramework, buildFileGroups); | ||
|
||
// TODO: Need to handle References element?? | ||
|
||
// Step-4: Raise PackageUninstalling event | ||
if (PackageUninstalling != null) | ||
{ | ||
PackageUninstalling(this, packageEventArgs); | ||
} | ||
PackageEventsProvider.Instance.NotifyUninstalling(packageEventArgs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this move up and be along with 'PackageUninstalling' event too? |
||
|
||
// Step-5: Uninstall package from packages.config | ||
// Step-5: Remove package reference from packages.config | ||
await PackagesConfigNuGetProject.UninstallPackageAsync(packageIdentity, nuGetProjectContext, token); | ||
|
||
// Step-6: Remove packages.config from MSBuildNuGetProject if there are no packages | ||
|
@@ -484,38 +482,27 @@ public override async Task<bool> UninstallPackageAsync(PackageIdentity packageId | |
} | ||
|
||
// Step-7.5: Remove binding redirects. This is a no-op | ||
// Binding redirects will be removed when all packages have finished | ||
// uninstalling for performance reasons | ||
|
||
// Step-8: Raise PackageReferenceRemoved event | ||
if (PackageReferenceRemoved != null) | ||
{ | ||
PackageReferenceRemoved(this, packageEventArgs); | ||
} | ||
PackageEventsProvider.Instance.NotifyReferenceRemoved(packageEventArgs); | ||
|
||
// Step-9: Execute powershell script - uninstall.ps1 | ||
var toolItemGroups = packageReader.GetToolItems(); | ||
var compatibleToolItemsGroup = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(packageTargetFramework, | ||
toolItemGroups); | ||
if (MSBuildNuGetProjectSystemUtility.IsValid(compatibleToolItemsGroup)) | ||
{ | ||
var uninstallPS1RelativePath = compatibleToolItemsGroup.Items.FirstOrDefault( | ||
p => p.EndsWith(Path.DirectorySeparatorChar + PowerShellScripts.Uninstall, StringComparison.OrdinalIgnoreCase)); | ||
if (!string.IsNullOrEmpty(uninstallPS1RelativePath)) | ||
{ | ||
var packageInstallPath = FolderNuGetProject.GetInstalledPath(packageIdentity); | ||
await MSBuildNuGetProjectSystem.ExecuteScriptAsync(packageIdentity, packageInstallPath, uninstallPS1RelativePath, this, throwOnFailure: false); | ||
} | ||
} | ||
PackageEventsProvider.Instance.NotifyReferenceRemoved(packageEventArgs); | ||
} | ||
|
||
// Step-10: Uninstall package from the folderNuGetProject | ||
// Step-9: Uninstall package from the folderNuGetProject | ||
await FolderNuGetProject.UninstallPackageAsync(packageIdentity, nuGetProjectContext, token); | ||
|
||
// Step-11: Raise PackageUninstalled event | ||
// Step-10: Raise PackageUninstalled event | ||
if (PackageUninstalled != null) | ||
{ | ||
PackageUninstalled(this, packageEventArgs); | ||
} | ||
|
||
PackageEventsProvider.Instance.NotifyUninstalled(packageEventArgs); | ||
|
||
return true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please break long lines (since the lines are moved anyways)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k