Skip to content

Commit da3ae7c

Browse files
authored
Use different versions of MSBuild and NuGet (#152)
1 parent a41e363 commit da3ae7c

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

Packages.props

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<MicrosoftBuildPackageVersion>16.11.0</MicrosoftBuildPackageVersion>
4+
<MicrosoftBuildPackageVersion>17.0.0</MicrosoftBuildPackageVersion>
5+
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net5.0'">16.11.0</MicrosoftBuildPackageVersion>
56
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'netcoreapp3.1'">16.9.0</MicrosoftBuildPackageVersion>
6-
<NuGetPackageVersion>5.11.0</NuGetPackageVersion>
7-
<NuGetPackageVersion Condition="'$(TargetFramework)' == 'net6.0'">6.0.0</NuGetPackageVersion>
7+
<NuGetPackageVersion>6.0.0</NuGetPackageVersion>
8+
<NuGetPackageVersion Condition="'$(TargetFramework)' == 'net5.0'">5.11.0</NuGetPackageVersion>
9+
<NuGetPackageVersion Condition="'$(TargetFramework)' == 'netcoreapp3.1'">5.7.1</NuGetPackageVersion>
810
</PropertyGroup>
911
<ItemGroup>
1012
<PackageReference Update="Microsoft.Build" Version="$(MicrosoftBuildPackageVersion)" />

src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/RepositoryTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests.PackageRepositoryT
1515
{
1616
public class RepositoryTests : TestBase
1717
{
18+
#if !NET6_0
1819
[Fact]
1920
public void BuildCanConsumePackage()
2021
{
@@ -34,6 +35,7 @@ public void BuildCanConsumePackage()
3435
result.ShouldBeTrue(buildOutput.GetConsoleLog());
3536
}
3637
}
38+
#endif
3739

3840
[Fact]
3941
public void BasicPackage()

src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SdkCsprojTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests
99
{
1010
public class SdkCsprojTests : TestBase
1111
{
12+
#if !NET6_0
1213
[Fact]
1314
public void CanBuild()
1415
{
@@ -20,6 +21,7 @@ public void CanBuild()
2021

2122
result.ShouldBeTrue(buildOutput.GetConsoleLog());
2223
}
24+
#endif
2325

2426
[Fact]
2527
public void CustomSdk()

src/Microsoft.Build.Utilities.ProjectCreation/Package.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,17 @@ internal void Save(DirectoryInfo rootPath)
331331
/// <param name="packageFile">An <see cref="IPackageFile" /> that represents a file to add to the package.</param>
332332
private void AddFile(string relativePath, IPackageFile packageFile)
333333
{
334+
#if NETCOREAPP3_1
335+
if (packageFile.TargetFramework != null)
336+
{
337+
AddTargetFramework(NuGetFramework.ParseFrameworkName(packageFile.TargetFramework.FullName, DefaultFrameworkNameProvider.Instance));
338+
}
339+
#else
334340
if (packageFile.NuGetFramework != null)
335341
{
336342
AddTargetFramework(packageFile.NuGetFramework);
337343
}
344+
#endif
338345

339346
_files[relativePath] = packageFile;
340347

src/Microsoft.Build.Utilities.ProjectCreation/PackageFileStream.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ public PackageFileStream(string targetPath, Func<Stream> streamFunc)
2727
{
2828
_path = string.Empty;
2929
EffectivePath = string.Empty;
30+
#if !NETCOREAPP3_1
3031
NuGetFramework = NuGetFramework.AnyFramework;
31-
TargetFramework = new FrameworkName(NuGetFramework.DotNetFrameworkName);
32+
#endif
33+
TargetFramework = new FrameworkName("Any, Version=1.0");
3234

3335
Path = targetPath;
3436
_streamFunc = streamFunc ?? throw new ArgumentNullException(nameof(streamFunc));
@@ -53,8 +55,10 @@ public PackageFileStream(string targetPath, FileInfo fileInfo)
5355
/// <inheritdoc />
5456
public DateTimeOffset LastWriteTime { get; }
5557

58+
#if !NETCOREAPP3_1
5659
/// <inheritdoc />
5760
public NuGetFramework NuGetFramework { get; private set; }
61+
#endif
5862

5963
/// <inheritdoc />
6064
public string Path
@@ -69,14 +73,15 @@ public string Path
6973
}
7074

7175
_path = value;
72-
76+
#if NETCOREAPP3_1
77+
TargetFramework = FrameworkNameUtility.ParseFrameworkNameFromFilePath(_path, out string effectivePath);
78+
#else
7379
NuGetFramework = FrameworkNameUtility.ParseNuGetFrameworkFromFilePath(_path, out string effectivePath);
74-
7580
if (NuGetFramework != null && NuGetFramework.Version.Major < 5)
7681
{
7782
TargetFramework = new FrameworkName(NuGetFramework.DotNetFrameworkName);
7883
}
79-
84+
#endif
8085
EffectivePath = effectivePath;
8186
}
8287
}

0 commit comments

Comments
 (0)