Skip to content

Commit

Permalink
Create test for old NuGet
Browse files Browse the repository at this point in the history
GeneratePathProperty does not work as seen in NuGet/Home#8476. Use workaround.
  • Loading branch information
Forgind committed May 26, 2020
1 parent 70c00b4 commit 1aa0d55
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Build.OM.UnitTests/Microsoft.Build.Engine.OM.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup>
<NuGetCommandLinePackageVersion>4.1.0</NuGetCommandLinePackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Shouldly" />
<PackageDownload Include="NuGet.CommandLine" Version="[$(NuGetCommandLinePackageVersion)]" />
</ItemGroup>

<ItemGroup>
<!-- GeneratePathProperty currently isn't enabled for PackageDownload. -->
<Content Condition="'$(MSBuildRuntimeType)' != 'Core' and '$(Configuration)' == 'Release'" Include="$(NuGetPackageRoot)\nuget.commandline\$(NuGetCommandLinePackageVersion)\tools\NuGet.exe" CopyToOutputDirectory="PreserveNewest" Link="nuget\NuGet.exe" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
Expand Down Expand Up @@ -94,6 +104,7 @@
<Compile Include="..\Shared\UnitTests\TestData\GlobbingTestData.cs">
<Link>TestData\GlobbingTestData.cs</Link>
</Compile>
<Compile Include="..\UnitTests.Shared\RunnerUtilities.cs" />

<None Include="..\Shared\UnitTests\App.config">
<Link>App.config</Link>
Expand Down
57 changes: 57 additions & 0 deletions src/Build.OM.UnitTests/NugetRestoreTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Build.UnitTests;
using Microsoft.Build.UnitTests.Shared;
using Shouldly;
using System.IO;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Build.Engine.OM.UnitTests
{
public sealed class NugetRestoreTests
{
private ITestOutputHelper _output;
public NugetRestoreTests(ITestOutputHelper output)
{
_output = output;
}

// This NuGet version cannot locate other assemblies when parsing solutions at restore time. This includes localized strings required in debug mode.
// NuGet version 4.1.0 was somewhat arbitrarily chosen. 3.5 breaks with an unrelated error, and 4.8.2 does not fail when a new dependency is introduced. This is a safe middle point.
#if !DEBUG
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp)]
[Fact]
public void TestOldNuget()
{
string msbuildExePath = Path.GetDirectoryName(RunnerUtilities.PathToCurrentlyRunningMsBuildExe);
using TestEnvironment testEnvironment = TestEnvironment.Create();
TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: true);
// The content of the solution isn't known to matter, but having a custom solution makes it easier to add requirements should they become evident.
TransientTestFile sln = testEnvironment.CreateFile(folder, "test.sln",
@"
Microsoft Visual Studio Solution File, Format Version 12.00
\# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
");
RunnerUtilities.RunProcessAndGetOutput(Path.Combine(msbuildExePath, "nuget", "NuGet.exe"), "restore " + sln.Path + " -MSBuildPath \"" + msbuildExePath + "\"", out bool success, outputHelper: _output);
success.ShouldBeTrue();
}
#endif
}
}

0 comments on commit 1aa0d55

Please sign in to comment.