Browse Source
Add Restore Packages menu item which executes "NuGet.exe restore" to restore all packages in the solution.pull/62/merge
14 changed files with 236 additions and 3 deletions
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<PrepareForRunDependsOn>$(PrepareForRunDependsOn);MyPostBuildTarget</PrepareForRunDependsOn> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<MyCopyItem Include="$(MSBuildProjectDirectory)\..\RequiredLibraries\NuGet.exe" /> |
||||
</ItemGroup> |
||||
<Target Name="MyPostBuildTarget"> |
||||
<!-- work around an MSBuild bug in CopyToOutputDirectory that causes this file to be copied --> |
||||
<!-- to projects referencing this project even if local copy on that reference is false --> |
||||
<Copy SourceFiles="@(MyCopyItem)" DestinationFolder="$(OutputPath)" /> |
||||
</Target> |
||||
</Project> |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public static class NuGetExePath |
||||
{ |
||||
public static string GetPath() |
||||
{ |
||||
return Path.Combine(GetDirectory(), "NuGet.exe"); |
||||
} |
||||
|
||||
static string GetDirectory() |
||||
{ |
||||
return Path.GetDirectoryName(typeof(NuGetExePath).Assembly.Location); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class NuGetPackageRestoreCommandLine |
||||
{ |
||||
public NuGetPackageRestoreCommandLine(IPackageManagementSolution solution) |
||||
{ |
||||
GenerateCommandLine(solution); |
||||
} |
||||
|
||||
public string Command { get; set; } |
||||
public string Arguments { get; private set; } |
||||
|
||||
void GenerateCommandLine(IPackageManagementSolution solution) |
||||
{ |
||||
Arguments = String.Format("restore \"{0}\"", solution.FileName); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("{0} {1}", GetQuotedCommand(), Arguments); |
||||
} |
||||
|
||||
string GetQuotedCommand() |
||||
{ |
||||
return String.Format("\"{0}\"", Command); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Util; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class RestorePackagesCommand : AbstractMenuCommand |
||||
{ |
||||
IPackageManagementOutputMessagesView outputMessagesView; |
||||
IPackageManagementSolution solution; |
||||
|
||||
public RestorePackagesCommand() |
||||
: this(PackageManagementServices.OutputMessagesView, PackageManagementServices.Solution) |
||||
{ |
||||
} |
||||
|
||||
public RestorePackagesCommand( |
||||
IPackageManagementOutputMessagesView outputMessagesView, |
||||
IPackageManagementSolution solution) |
||||
{ |
||||
this.outputMessagesView = outputMessagesView; |
||||
this.solution = solution; |
||||
} |
||||
|
||||
public override void Run() |
||||
{ |
||||
try { |
||||
ClearOutputWindow(); |
||||
BringOutputWindowToFront(); |
||||
RunRestore(); |
||||
} catch (Exception ex) { |
||||
LoggingService.Debug(ex.ToString()); |
||||
outputMessagesView.AppendLine(ex.Message); |
||||
} |
||||
} |
||||
|
||||
void ClearOutputWindow() |
||||
{ |
||||
outputMessagesView.Clear(); |
||||
} |
||||
|
||||
void BringOutputWindowToFront() |
||||
{ |
||||
CompilerMessageView.Instance.BringToFront(); |
||||
} |
||||
|
||||
void RunRestore() |
||||
{ |
||||
var commandLine = new NuGetPackageRestoreCommandLine(solution); |
||||
commandLine.Command = NuGetExePath.GetPath(); |
||||
|
||||
outputMessagesView.AppendLine(commandLine.ToString()); |
||||
|
||||
ProcessRunner runner = CreateProcessRunner(); |
||||
runner.WorkingDirectory = Path.GetDirectoryName(solution.FileName); |
||||
runner.Start(commandLine.Command, commandLine.Arguments); |
||||
} |
||||
|
||||
ProcessRunner CreateProcessRunner() |
||||
{ |
||||
var runner = new ProcessRunner(); |
||||
runner.LogStandardOutputAndError = false; |
||||
runner.OutputLineReceived += (sender, e) => outputMessagesView.AppendLine(e.Line); |
||||
runner.ErrorLineReceived += (sender, e) => outputMessagesView.AppendLine(e.Line); |
||||
runner.ProcessExited += (sender, e) => { |
||||
if (runner.ExitCode != 0) { |
||||
outputMessagesView.AppendLine("Exit code " + runner.ExitCode); |
||||
} |
||||
}; |
||||
return runner; |
||||
} |
||||
} |
||||
} |
Binary file not shown.
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement; |
||||
using NUnit.Framework; |
||||
using Rhino.Mocks; |
||||
|
||||
namespace PackageManagement.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class NuGetPackageRestoreCommandLineTests |
||||
{ |
||||
NuGetPackageRestoreCommandLine commandLine; |
||||
|
||||
void CreateCommandLineWithSolution(string fileName) |
||||
{ |
||||
IPackageManagementSolution solution = MockRepository.GenerateStub<IPackageManagementSolution>(); |
||||
solution.Stub(s => s.FileName).Return(fileName); |
||||
commandLine = new NuGetPackageRestoreCommandLine(solution); |
||||
} |
||||
|
||||
[Test] |
||||
public void Arguments_RestoreSolution_SolutionFullFileNameUsed() |
||||
{ |
||||
CreateCommandLineWithSolution(@"d:\projects\MySolution\MySolution.sln"); |
||||
|
||||
string arguments = commandLine.Arguments; |
||||
|
||||
Assert.AreEqual("restore \"d:\\projects\\MySolution\\MySolution.sln\"", arguments); |
||||
} |
||||
|
||||
[Test] |
||||
public void ToString_RestoreSolution_FullCommandLineReturned() |
||||
{ |
||||
CreateCommandLineWithSolution(@"d:\projects\MySolution\MySolution.sln"); |
||||
commandLine.Command = @"d:\sharpdevelop\NuGet.exe"; |
||||
|
||||
string fullCommandLine = commandLine.ToString(); |
||||
|
||||
Assert.AreEqual("\"d:\\sharpdevelop\\NuGet.exe\" restore \"d:\\projects\\MySolution\\MySolution.sln\"", fullCommandLine); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue