Skip to content

Commit

Permalink
add slnx support
Browse files Browse the repository at this point in the history
  • Loading branch information
sensslen committed Dec 27, 2024
1 parent d4c59df commit e8f0f30
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
- name: build
run: msbuild -t:rebuild -property:Configuration=TestWindows

- name: test
- name: test (${{ matrix.framework }})
uses: josepho0918/vstest-action@main
with:
testAssembly: "NuGetUtility.Test.dll"
Expand Down
4 changes: 2 additions & 2 deletions src/NuGetUtility/NuGetUtility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.12.*" />
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.11.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
Expand All @@ -48,7 +48,7 @@
<PackageReference Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.12.*" />
<PackageReference Include="PolySharp" Version="1.14.*">
<PackageReference Include="PolySharp" Version="1.15.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ProjectsCollector(IMsBuildAbstraction msBuild)

public IEnumerable<string> GetProjects(string inputPath)
{
return Path.GetExtension(inputPath).Equals(".sln")
return Path.GetExtension(inputPath).StartsWith(".sln")
? _msBuild.GetProjectsFromSolution(Path.GetFullPath(inputPath)).Where(File.Exists).Select(Path.GetFullPath)
: new[] { Path.GetFullPath(inputPath) };
}
Expand Down
2 changes: 1 addition & 1 deletion tests/NuGetUtility.Test/NuGetUtility.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<PackageReference Include="PolySharp" Version="1.14.*">
<PackageReference Include="PolySharp" Version="1.15.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{SolutionDirectory}tests\targets\PackageReferenceProject\PackageReferenceProject.csproj,{SolutionDirectory}tests\targets\PackagesConfigProject\PackagesConfigProject.csproj,{SolutionDirectory}tests\targets\ProjectWithoutNugetReferences\ProjectWithoutNugetReferences.csproj,{SolutionDirectory}tests\targets\ProjectWithTransitiveNuget\ProjectWithTransitiveNuget.csproj,{SolutionDirectory}tests\targets\ProjectWithTransitiveReferences\ProjectWithTransitiveReferences.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void GetProjects_Should_ReturnProjectsAsListDirectly(string projectFile)
[TestCase("A.sln")]
[TestCase("B.sln")]
[TestCase("C.sln")]
[TestCase("A.slnx")]
public void GetProjects_Should_QueryMsBuildToGetProjectsForSolutionFiles(string solutionFile)
{
_ = _uut.GetProjects(solutionFile);
Expand All @@ -48,6 +49,7 @@ public void GetProjects_Should_QueryMsBuildToGetProjectsForSolutionFiles(string
[TestCase("A.sln")]
[TestCase("B.sln")]
[TestCase("C.sln")]
[TestCase("C.slnx")]
public void GetProjects_Should_ReturnEmptyArray_If_SolutionContainsNoProjects(string solutionFile)
{
_msBuild.GetProjectsFromSolution(Arg.Any<string>()).Returns(Enumerable.Empty<string>());
Expand All @@ -61,6 +63,7 @@ public void GetProjects_Should_ReturnEmptyArray_If_SolutionContainsNoProjects(st
[TestCase("A.sln")]
[TestCase("B.sln")]
[TestCase("C.sln")]
[TestCase("B.slnx")]
public void GetProjects_Should_ReturnEmptyArray_If_SolutionContainsProjectsThatDontExist(string solutionFile)
{
IEnumerable<string> projects = _fixture.CreateMany<string>();
Expand All @@ -75,6 +78,7 @@ public void GetProjects_Should_ReturnEmptyArray_If_SolutionContainsProjectsThatD
[TestCase("A.sln")]
[TestCase("B.sln")]
[TestCase("C.sln")]
[TestCase("C.slnx")]
public void GetProjects_Should_ReturnArrayOfProjects_If_SolutionContainsProjectsThatDoExist(string solutionFile)
{
string[] projects = _fixture.CreateMany<string>().ToArray();
Expand All @@ -90,6 +94,7 @@ public void GetProjects_Should_ReturnArrayOfProjects_If_SolutionContainsProjects
[TestCase("A.sln")]
[TestCase("B.sln")]
[TestCase("C.sln")]
[TestCase("A.slnx")]
public void GetProjects_Should_ReturnOnlyExistingProjectsInSolutionFile(string solutionFile)
{
string[] existingProjects = _fixture.CreateMany<string>().ToArray();
Expand All @@ -114,15 +119,23 @@ public void GetProjectsFromSolution_Should_ReturnProjectsInActualSolutionFileRel
Assert.That(result.Count(), Is.EqualTo(5));
}

[Test, Ignore("Ignore this specific test as long as msbuild does not fully support slnx solutions everywhere")]
public async Task GetProjectsFromXmlSolution_Should_ReturnProjectsInActualSolutionFileRelativePath()
{
var msbuild = new MsBuildAbstraction();
IEnumerable<string> result = msbuild.GetProjectsFromSolution("../../../../targets/slnx/slnx.slnx");
await Verify(string.Join(",", result));
}

[Test]
public void GetProjectsFromSolution_Should_ReturnProjectsInActualSolutionFileAbsolutePath()
public async Task GetProjectsFromSolution_Should_ReturnProjectsInActualSolutionFileAbsolutePath()
{
var msbuild = new MsBuildAbstraction();
IEnumerable<string> result = msbuild.GetProjectsFromSolution(Path.GetFullPath("../../../../targets/Projects.sln"));
Assert.That(result.Count(), Is.EqualTo(5));
await Verify(string.Join(",", result));
}

private void CreateFiles(IEnumerable<string> files)
private static void CreateFiles(IEnumerable<string> files)
{
foreach (string file in files)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void GetInstalledPackagesShould_ReturnResolvedDependency_For_ProjectWithR

IEnumerable<PackageIdentity> result = _uut!.GetInstalledPackages(path, includeTransitive);

Assert.That(result.Count, Is.EqualTo(includeTransitive ? 2 : 1));
Assert.That(result.Count, Is.EqualTo(includeTransitive ? 3 : 1));
}

[Test]
Expand Down Expand Up @@ -155,15 +155,15 @@ public void GetInstalledPackagesShould_ThrowError_For_PackagesForNativeCppProjec
[TestCase("net8.0", false, "Microsoft.Extensions.Logging.Abstractions")]
[TestCase("net8.0-browser", false, "Microsoft.Extensions.Logging.Abstractions")]
[TestCase("net6.0", true, "TinyCsvParser")]
[TestCase("net8.0", true, "Microsoft.Extensions.Logging.Abstractions", "Microsoft.Extensions.DependencyInjection.Abstractions")]
[TestCase("net8.0-browser", true, "Microsoft.Extensions.Logging.Abstractions", "Microsoft.Extensions.DependencyInjection.Abstractions")]
[TestCase("net8.0", true, "Microsoft.Extensions.Logging.Abstractions", "Microsoft.Extensions.DependencyInjection.Abstractions", "System.Diagnostics.DiagnosticSource")]
[TestCase("net8.0-browser", true, "Microsoft.Extensions.Logging.Abstractions", "Microsoft.Extensions.DependencyInjection.Abstractions", "System.Diagnostics.DiagnosticSource")]
public void GetInstalledPackagesShould_OnlyReturn_PackagesPackagesReferencedByRequestedFramework(string framework, bool includeTransitive, params string[] packages)
{
string path = Path.GetFullPath("../../../../targets/MultiTargetProjectWithDifferentDependencies/MultiTargetProjectWithDifferentDependencies.csproj");

IEnumerable<PackageIdentity> result = _uut!.GetInstalledPackages(path, includeTransitive, framework);

Assert.That(packages, Is.EquivalentTo(result.Select(p => p.Id)));
Assert.That(result.Select(p => p.Id), Is.EquivalentTo(packages));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<PackageReference Include="TinyCsvParser" Version="2.7.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-browser'">
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.*" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="TinyCsvParser, Version=2.7.0.0, Culture=neutral, PublicKeyToken=d7df35b038077099, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\TinyCsvParser.2.7.0\lib\netstandard2.0\TinyCsvParser.dll</HintPath>
<Reference Include="TinyCsvParser, Version=2.7.1.0, Culture=neutral, PublicKeyToken=d7df35b038077099, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\TinyCsvParser.2.7.1\lib\netstandard2.0\TinyCsvParser.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/targets/PackagesConfigProject/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="TinyCsvParser" version="2.7.0" targetFramework="net472" />
<package id="TinyCsvParser" version="2.7.1" targetFramework="net472" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="[8.0.2]" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="[9.0.0]" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions tests/targets/slnx/slnx.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Solution>
<Configurations>
<BuildType Name="Debug" />
<BuildType Name="Release" />
<BuildType Name="TestWindows" />
</Configurations>
<Project Path="../ProjectWithTransitiveNuget/ProjectWithTransitiveNuget.csproj" Id="875c0575-95c4-4006-a910-bb1555c90c75" />
</Solution>

0 comments on commit e8f0f30

Please sign in to comment.