Skip to content

Commit

Permalink
Use different versions of MSBuild and NuGet
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Feb 15, 2022
1 parent a41e363 commit c01a865
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Packages.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MicrosoftBuildPackageVersion>16.11.0</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion>17.0.0</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net5.0'">16.11.0</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'netcoreapp3.1'">16.9.0</MicrosoftBuildPackageVersion>
<NuGetPackageVersion>5.11.0</NuGetPackageVersion>
<NuGetPackageVersion Condition="'$(TargetFramework)' == 'net6.0'">6.0.0</NuGetPackageVersion>
<NuGetPackageVersion>6.0.0</NuGetPackageVersion>
<NuGetPackageVersion Condition="'$(TargetFramework)' == 'net5.0'">5.11.0</NuGetPackageVersion>
<NuGetPackageVersion Condition="'$(TargetFramework)' == 'netcoreapp3.1'">5.7.1</NuGetPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Update="Microsoft.Build" Version="$(MicrosoftBuildPackageVersion)" />
Expand Down
7 changes: 7 additions & 0 deletions src/Microsoft.Build.Utilities.ProjectCreation/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,17 @@ internal void Save(DirectoryInfo rootPath)
/// <param name="packageFile">An <see cref="IPackageFile" /> that represents a file to add to the package.</param>
private void AddFile(string relativePath, IPackageFile packageFile)
{
#if NETCOREAPP3_1
if (packageFile.TargetFramework != null)
{
AddTargetFramework(NuGetFramework.ParseFrameworkName(packageFile.TargetFramework.FullName, DefaultFrameworkNameProvider.Instance));
}
#else
if (packageFile.NuGetFramework != null)
{
AddTargetFramework(packageFile.NuGetFramework);
}
#endif

_files[relativePath] = packageFile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public PackageFileStream(string targetPath, Func<Stream> streamFunc)
{
_path = string.Empty;
EffectivePath = string.Empty;
#if !NETCOREAPP3_1
NuGetFramework = NuGetFramework.AnyFramework;
TargetFramework = new FrameworkName(NuGetFramework.DotNetFrameworkName);
#endif
TargetFramework = new FrameworkName("Any, Version=1.0");

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

#if !NETCOREAPP3_1
/// <inheritdoc />
public NuGetFramework NuGetFramework { get; private set; }
#endif

/// <inheritdoc />
public string Path
Expand All @@ -69,14 +73,15 @@ public string Path
}

_path = value;

#if NETCOREAPP3_1
TargetFramework = FrameworkNameUtility.ParseFrameworkNameFromFilePath(_path, out string effectivePath);
#else
NuGetFramework = FrameworkNameUtility.ParseNuGetFrameworkFromFilePath(_path, out string effectivePath);

if (NuGetFramework != null && NuGetFramework.Version.Major < 5)
{
TargetFramework = new FrameworkName(NuGetFramework.DotNetFrameworkName);
}

#endif
EffectivePath = effectivePath;
}
}
Expand Down

0 comments on commit c01a865

Please sign in to comment.