forked from tomchavakis/nuget-license
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly test packages.config feature
- Loading branch information
Showing
11 changed files
with
155 additions
and
52 deletions.
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
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
45 changes: 45 additions & 0 deletions
45
src/NuGetUtility/Wrapper/MsBuildWrapper/WindowsMsBuildAbstraction.cs
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Management; | ||
using System.Runtime.Versioning; | ||
|
||
namespace NuGetUtility.Wrapper.MsBuildWrapper | ||
{ | ||
[SupportedOSPlatform("windows")] | ||
public class WindowsMsBuildAbstraction : MsBuildAbstraction | ||
{ | ||
public WindowsMsBuildAbstraction() | ||
{ | ||
// to support VC-projects we need to workaround : https://github.com/3F/MvsSln/issues/1 | ||
// adding 'VCTargetsPath' to Project::GlobalProperties seem to be enough | ||
|
||
if (GetBestVCTargetsPath() is string path) | ||
{ | ||
AddGlobalProjectProperty("VCTargetsPath", $"{path}\\"); | ||
} | ||
} | ||
|
||
private static string? GetBestVCTargetsPath() | ||
{ | ||
var cppProperties = new List<FileInfo>(); | ||
|
||
foreach (string path in GetVisualStudioInstallPaths()) | ||
cppProperties.AddRange(new DirectoryInfo(path).GetFiles("Microsoft.Cpp.Default.props", SearchOption.AllDirectories)); | ||
|
||
// if multiple, assume most recent 'LastWriteTime' property is 'best' | ||
return cppProperties.OrderBy(f => f.LastWriteTime).LastOrDefault()?.DirectoryName; | ||
} | ||
|
||
private static IEnumerable<string> GetVisualStudioInstallPaths() | ||
{ | ||
// https://learn.microsoft.com/en-us/visualstudio/install/tools-for-managing-visual-studio-instances?view=vs-2022#using-windows-management-instrumentation-wmi | ||
|
||
var result = new List<string>(); | ||
var mmc = new ManagementClass("root/cimv2/vs:MSFT_VSInstance"); | ||
|
||
foreach (ManagementBaseObject? vs_instance in mmc.GetInstances()) | ||
if (vs_instance["InstallLocation"] is string install_path) | ||
result.Add(install_path); | ||
|
||
return result; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/NuGetUtility/Wrapper/NuGetWrapper/Packaging/Core/FailingPackagesConfigReader.cs
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using NuGetUtility.Wrapper.MsBuildWrapper; | ||
|
||
namespace NuGetUtility.Wrapper.NuGetWrapper.Packaging.Core | ||
{ | ||
public class FailingPackagesConfigReader : IPackagesConfigReader | ||
{ | ||
public IEnumerable<PackageIdentity> GetPackages(IProject project) | ||
{ | ||
throw new PackagesConfigReaderException($"Invalid project structure detected. Currently packages.config projects are only supported on Windows (Project: {project.FullPath})"); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/NuGetUtility/Wrapper/NuGetWrapper/Packaging/Core/IPackagesConfigReader.cs
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using NuGetUtility.Wrapper.MsBuildWrapper; | ||
|
||
namespace NuGetUtility.Wrapper.NuGetWrapper.Packaging.Core | ||
{ | ||
public interface IPackagesConfigReader | ||
{ | ||
IEnumerable<PackageIdentity> GetPackages(IProject project); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/NuGetUtility/Wrapper/NuGetWrapper/Packaging/Core/PackagesConfigReaderException.cs
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace NuGetUtility.Wrapper.NuGetWrapper.Packaging.Core | ||
{ | ||
public class PackagesConfigReaderException : Exception | ||
{ | ||
public PackagesConfigReaderException(string? message) : base(message) { } | ||
} | ||
} |
10 changes: 6 additions & 4 deletions
10
...per/Packaging/Core/PackageConfigReader.cs → ...aging/Core/WindowsPackagesConfigReader.cs
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
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