Skip to content
This repository was archived by the owner on Nov 27, 2019. It is now read-only.

Commit b83ab81

Browse files
committed
Support target framework specific NuGet PowerShell scripts.
Fix AutoMapper NuGet PowerShell scripts not being run. A NuGet package can have install.ps1 and uninstall.ps1 PowerShell scripts that target a particular framework based on the tools subdirectory where they can be placed: tools\net40\install.ps1 tools\net40\uninstall.ps1 Previously SharpDevelop would only look in the tools directory for these scripts. Now it will use the project's target framework to find the most compatible PowerShell install or uninstall script. Note that NuGet does not support init.ps1 being target framework specific and it will only be run if it exists in the tools directory inside the NuGet package.
1 parent e5b17a3 commit b83ab81

14 files changed

+216
-10
lines changed

src/AddIns/Misc/PackageManagement/Project/Src/Design/FakeFileSystem.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ public IEnumerable<string> GetDirectories(string path)
5959

6060
public string GetFullPath(string path)
6161
{
62-
return PathToReturnFromGetFullPath;
62+
if (PathToReturnFromGetFullPath != null) {
63+
return PathToReturnFromGetFullPath;
64+
} else if (Root == null) {
65+
return null;
66+
}
67+
return Path.Combine(Root, path);
6368
}
6469

6570
public void DeleteFile(string path)
@@ -70,9 +75,16 @@ public void DeleteFile(string path)
7075
public bool FileExists(string path)
7176
{
7277
PathPassedToFileExists = path;
78+
79+
if (ExistingFiles.Contains(path)) {
80+
return true;
81+
}
82+
7383
return FileExistsReturnValue;
7484
}
7585

86+
public List<string> ExistingFiles = new List<string>();
87+
7688
public bool DirectoryExists(string path)
7789
{
7890
PathPassedToDirectoryExists = path;

src/AddIns/Misc/PackageManagement/Project/Src/Design/FakePackageManagementProject.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Collections.Generic;
2121
using System.Linq;
2222

23+
using System.Runtime.Versioning;
2324
using ICSharpCode.PackageManagement;
2425
using ICSharpCode.PackageManagement.EnvDTE;
2526
using NuGet;
@@ -41,6 +42,7 @@ public FakePackageManagementProject(string name)
4142
this.Name = name;
4243

4344
ConstraintProvider = NullConstraintProvider.Instance;
45+
TargetFramework = new FrameworkName(".NETFramework", new Version("4.0"));
4446
}
4547

4648
private FakeInstallPackageAction FakeInstallPackageAction;
@@ -283,5 +285,7 @@ public void UpdatePackageReference(IPackage package, IUpdatePackageSettings sett
283285
}
284286

285287
public IPackageConstraintProvider ConstraintProvider { get; set; }
288+
289+
public FrameworkName TargetFramework { get; set; }
286290
}
287291
}

src/AddIns/Misc/PackageManagement/Project/Src/IPackageManagementProject.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Collections.Generic;
2121
using System.Linq;
2222

23+
using System.Runtime.Versioning;
2324
using ICSharpCode.PackageManagement.EnvDTE;
2425
using NuGet;
2526

@@ -33,6 +34,7 @@ public interface IPackageManagementProject
3334
event EventHandler<PackageOperationEventArgs> PackageReferenceRemoving;
3435

3536
string Name { get; }
37+
FrameworkName TargetFramework { get; }
3638
ILogger Logger { get; set; }
3739
IPackageRepository SourceRepository { get; }
3840

src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementProject.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Collections.Generic;
2121
using System.Linq;
2222

23+
using System.Runtime.Versioning;
2324
using ICSharpCode.PackageManagement.EnvDTE;
2425
using ICSharpCode.SharpDevelop.Project;
2526
using NuGet;
@@ -32,6 +33,7 @@ public class PackageManagementProject : IPackageManagementProject
3233
ISharpDevelopProjectManager projectManager;
3334
IPackageManagementEvents packageManagementEvents;
3435
MSBuildBasedProject msbuildProject;
36+
ProjectTargetFramework targetFramework;
3537

3638
public PackageManagementProject(
3739
IPackageRepository sourceRepository,
@@ -41,6 +43,7 @@ public PackageManagementProject(
4143
{
4244
SourceRepository = sourceRepository;
4345
msbuildProject = project;
46+
targetFramework = new ProjectTargetFramework(project);
4447
this.packageManagementEvents = packageManagementEvents;
4548

4649
packageManager = packageManagerFactory.CreatePackageManager(sourceRepository, project);
@@ -51,6 +54,10 @@ public string Name {
5154
get { return msbuildProject.Name; }
5255
}
5356

57+
public FrameworkName TargetFramework {
58+
get { return targetFramework.TargetFrameworkName; }
59+
}
60+
5461
public IPackageRepository SourceRepository { get; private set; }
5562

5663
public ILogger Logger {

src/AddIns/Misc/PackageManagement/Project/Src/Scripting/IPackageScriptFileName.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// DEALINGS IN THE SOFTWARE.
1818

1919
using System;
20+
using System.Runtime.Versioning;
21+
using NuGet;
2022

2123
namespace ICSharpCode.PackageManagement.Scripting
2224
{
@@ -27,5 +29,6 @@ public interface IPackageScriptFileName
2729
bool ScriptDirectoryExists();
2830
bool FileExists();
2931
string GetScriptDirectory();
32+
void UseTargetSpecificFileName(IPackage package, FrameworkName frameworkName);
3033
}
3134
}

src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageInstallScript.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class PackageInstallScript : PackageScript
2626
public PackageInstallScript(IPackage package, IPackageScriptFileName fileName)
2727
: base(package, fileName)
2828
{
29+
UseTargetSpecificScript = true;
2930
}
3031
}
3132
}

src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageScript.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@
1717
// DEALINGS IN THE SOFTWARE.
1818

1919
using System;
20+
using System.Collections.Generic;
21+
using System.Linq;
22+
using System.Runtime.Versioning;
2023
using ICSharpCode.PackageManagement.EnvDTE;
2124
using NuGet;
2225

2326
namespace ICSharpCode.PackageManagement.Scripting
2427
{
2528
public class PackageScript : IPackageScript
2629
{
30+
bool lookedForTargetSpecificScript;
31+
2732
public PackageScript(IPackage package, IPackageScriptFileName fileName)
2833
{
2934
this.Package = package;
@@ -32,12 +37,14 @@ public PackageScript(IPackage package, IPackageScriptFileName fileName)
3237

3338
protected IPackageScriptFileName ScriptFileName { get; private set; }
3439
protected IPackageScriptSession Session { get; private set; }
40+
protected bool UseTargetSpecificScript { get; set; }
3541

3642
public IPackage Package { get; set; }
3743
public IPackageManagementProject Project { get; set; }
3844

3945
public bool Exists()
4046
{
47+
FindTargetSpecificScriptFileName();
4148
return ScriptFileName.FileExists();
4249
}
4350

@@ -97,5 +104,18 @@ void RemoveSessionVariables()
97104
Session.RemoveVariable("__package");
98105
Session.RemoveVariable("__project");
99106
}
107+
108+
void FindTargetSpecificScriptFileName()
109+
{
110+
if (UseTargetSpecificScript && !lookedForTargetSpecificScript) {
111+
ScriptFileName.UseTargetSpecificFileName(Package, GetTargetFramework());
112+
lookedForTargetSpecificScript = true;
113+
}
114+
}
115+
116+
FrameworkName GetTargetFramework()
117+
{
118+
return Project.TargetFramework;
119+
}
100120
}
101121
}

src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageScriptFileName.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
// DEALINGS IN THE SOFTWARE.
1818

1919
using System;
20+
using System.Collections.Generic;
2021
using System.IO;
22+
using System.Linq;
23+
using System.Runtime.Versioning;
2124
using NuGet;
2225

2326
namespace ICSharpCode.PackageManagement.Scripting
@@ -68,5 +71,16 @@ public string GetScriptDirectory()
6871
{
6972
return fileSystem.GetFullPath("tools");
7073
}
74+
75+
public void UseTargetSpecificFileName(IPackage package, FrameworkName targetFramework)
76+
{
77+
IEnumerable<IPackageFile> files;
78+
if (VersionUtility.TryGetCompatibleItems(targetFramework, package.GetToolFiles(), out files)) {
79+
IPackageFile matchingScriptFile = files.FirstOrDefault(file => file.EffectivePath.Equals(Name, StringComparison.OrdinalIgnoreCase));
80+
if (matchingScriptFile != null) {
81+
relativeScriptFilePath = matchingScriptFile.Path;
82+
}
83+
}
84+
}
7185
}
7286
}

src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageUninstallScript.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class PackageUninstallScript : PackageScript
2626
public PackageUninstallScript(IPackage package, IPackageScriptFileName fileName)
2727
: base(package, fileName)
2828
{
29+
UseTargetSpecificScript = true;
2930
}
3031
}
3132
}

src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
<Compile Include="Src\Scripting\MSBuildProjectImportsMergerTests.cs" />
199199
<Compile Include="Src\Scripting\MSBuildProjectPropertiesMergerTests.cs" />
200200
<Compile Include="Src\Scripting\PackageManagementConsoleHostLoggerTests.cs" />
201+
<Compile Include="Src\Scripting\PackageUninstallScriptTests.cs" />
201202
<Compile Include="Src\SettingsProviderTests.cs" />
202203
<Compile Include="Src\UpdatedPackagesTests.cs" />
203204
<Compile Include="Src\UpdatePackagesActionTests.cs" />

0 commit comments

Comments
 (0)