Skip to content

Commit

Permalink
Support .NET 5
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Dec 11, 2020
1 parent 9ccf910 commit df3eb58
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 87 deletions.
1 change: 1 addition & 0 deletions MSBuildProjectCreator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{8339FD67
Packages.props = Packages.props
README.md = README.md
version.json = version.json
xunit.runner.json = xunit.runner.json
EndProjectSection
EndProject
Global
Expand Down
21 changes: 11 additions & 10 deletions Packages.props
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Update="Microsoft.Build" Version="16.3.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Update="Microsoft.VisualStudio.SDK.EmbedInteropTypes" Version="15.0.29" />
<PackageReference Update="Microsoft.Build" Version="16.8.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Update="Microsoft.VisualStudio.SDK.EmbedInteropTypes" Version="15.0.36" />
<PackageReference Update="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="1.16.30" />
<PackageReference Update="MSTest.TestAdapter" Version="1.1.18" />
<PackageReference Update="MSTest.TestFramework" Version="1.1.18" />
<PackageReference Update="NuGet.Packaging" Version="5.5.1" />
<PackageReference Update="NuGet.ProjectModel" Version="5.5.1" />
<PackageReference Update="Shouldly" Version="3.0.2" />
<PackageReference Update="NuGet.Frameworks" Version="5.8.0" />
<PackageReference Update="NuGet.Packaging" Version="5.8.0" />
<PackageReference Update="NuGet.ProjectModel" Version="5.8.0" />
<PackageReference Update="Shouldly" Version="4.0.1" />
<PackageReference Update="xunit" Version="2.4.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.3" />
</ItemGroup>

<ItemGroup>
<GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="2.0.1" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.0.26" Condition=" '$(EnableGitVersioning)' != 'false' " />
<GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="2.0.35" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.3.37" Condition=" '$(EnableGitVersioning)' != 'false' " />
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.1.118" Condition=" '$(EnableStyleCopAnalyzers)' != 'false' " />
</ItemGroup>

Expand Down
71 changes: 45 additions & 26 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,81 @@ resources:
- repo: self

variables:
ArtifactsDirectoryName: 'artifacts'
BuildConfiguration: 'Debug'
BuildPlatform: 'Any CPU'
DotNetCore3Version: '3.1.101'
DotNetCore2Version: '2.1.802'
DotNetCore3Version: '3.x'
DotNet5Version: '5.x'
MSBuildArgs: '"/p:Platform=$(BuildPlatform)" "/p:Configuration=$(BuildConfiguration)" "/BinaryLogger:$(Build.SourcesDirectory)\$(ArtifactsDirectoryName)\msbuild.binlog"'


trigger:
batch: true
batch: 'true'
branches:
include:
- 'master'
- 'refs/tags/*'
- 'rel/*'
paths:
exclude:
- README.md
- '*.md'
pr:
branches:
include:
- master
- 'master'
- 'rel/*'
paths:
exclude:
- README.md
- '*.md'

jobs:
- job: NETCoreWindows
displayName: Build (Windows)
- job: BuildAndTest
displayName: 'Build and Test'
pool:
vmImage: windows-latest
steps:
- script: 'echo ##vso[task.setvariable variable=BuildConfiguration;]Release'
displayName: 'Set BuildConfiguration to Release for tagged commits'
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))

- task: UseDotNet@2
displayName: 'Install .NET Core $(DotNetCore2Version)'
displayName: 'Install .NET Core $(DotNetCore3Version)'
inputs:
version: '$(DotNetCore2Version)'
version: '$(DotNetCore3Version)'

- task: UseDotNet@2
displayName: 'Install .NET Core $(DotNetCore3Version)'
displayName: 'Install .NET $(DotNet5Version)'
inputs:
version: '$(DotNetCore3Version)'
version: '$(DotNet5Version)'

- task: DotNetCoreCLI@2
displayName: 'Build Solution'
inputs:
command: 'build'
projects: 'MSBuildProjectCreator.sln'
arguments: '$(MSBuildArgs)'

- task: DotNetCoreCLI@2
displayName: 'Run Unit Tests (.NET 5)'
inputs:
command: 'test'
arguments: '--no-restore --no-build --framework net5.0 "/restore:false"'
testRunTitle: '.NET 5.0'

- task: DotNetCoreCLI@2
displayName: 'dotnet build'
displayName: 'Run Unit Tests (.NET Framework)'
condition: succeededOrFailed()
inputs:
arguments: '-property:"Configuration=$(BuildConfiguration)"'
command: 'test'
arguments: '--no-restore --no-build --framework net472 "/restore:false"'
testRunTitle: '.NET Framework 4.7.2'

- task: DotNetCoreCLI@2
displayName: 'dotnet test'
displayName: 'Run Unit Tests (.NET Core)'
condition: succeededOrFailed()
inputs:
command: test
arguments: '--no-build -restore:false -property:VSTestNoBuild=true -property:"Configuration=$(BuildConfiguration)"'
command: 'test'
arguments: '--no-restore --no-build --framework netcoreapp3.1 "/restore:false"'
testRunTitle: '.NET Core 3.1'

- task: PublishPipelineArtifact@0
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
artifactName: 'drop'
targetPath: 'artifacts'
condition: succeededOrFailed()
PathtoPublish: '$(ArtifactsDirectoryName)'
ArtifactName: $(ArtifactsDirectoryName)
condition: always()
6 changes: 3 additions & 3 deletions src/MSBuildProjectCreator.UnitTests/BuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void ProjectCollectionLoggersWork()

string fileLogContents = File.ReadAllText(fileLogPath);

fileLogContents.ShouldContain("2AE492F6EEE04255B31B088051E9AF0F", fileLogContents);
fileLogContents.ShouldContain("2AE492F6EEE04255B31B088051E9AF0F", Case.Sensitive, fileLogContents);
}

[Fact]
Expand Down Expand Up @@ -164,8 +164,8 @@ public void ProjectCollectionLoggersWorkWithRestore()

string fileLogContents = File.ReadAllText(fileLogPath);

fileLogContents.ShouldContain("38EC33B686134B3C8DE4B8E571D4FB24", fileLogContents);
fileLogContents.ShouldContain("B7F9A257198D4A44A06BB6146AB27440", fileLogContents);
fileLogContents.ShouldContain("38EC33B686134B3C8DE4B8E571D4FB24", Case.Sensitive, fileLogContents);
fileLogContents.ShouldContain("B7F9A257198D4A44A06BB6146AB27440", Case.Sensitive, fileLogContents);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp3.1;net5.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<AssemblyName>Microsoft.Build.Utilities.ProjectCreation.UnitTests</AssemblyName>
<RootNamespace>Microsoft.Build.Utilities.ProjectCreation.UnitTests</RootNamespace>
</PropertyGroup>
<Import Project="..\MSBuildProjectCreator\build\MSBuild.ProjectCreation.props" Condition="'$(TargetFramework)' == 'net472'" />
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NuGet.Packaging" IncludeAssets="All" />
<PackageReference Include="NuGet.ProjectModel" IncludeAssets="All" />
<PackageReference Include="NuGet.Frameworks" />
<PackageReference Include="NuGet.Packaging" ExcludeAssets="Runtime" />
<PackageReference Include="Shouldly" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />

<PackageReference Update="NuGet.Frameworks" VersionOverride="5.7.0" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" />
<PackageReference Update="NuGet.Packaging" VersionOverride="5.7.0" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MSBuildProjectCreator\MSBuildProjectCreator.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void CanAddMultipleDependenciesToSameGroup()

private void ValidatePackageDependencies(PackageIdentity package, IEnumerable<PackageDependencyGroup> expectedDependencyGroups)
{
FileInfo nuspecFile = new FileInfo(VersionFolderPathResolver.GetManifestFilePath(package.Id, package.Version));
FileInfo nuspecFile = new FileInfo(((VersionFolderPathResolver)VersionFolderPathResolver).GetManifestFilePath(package.Id, package.Version));

nuspecFile.ShouldExist();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// Licensed under the MIT license.

using NuGet.Packaging;
using NuGet.Packaging.Core;
using Shouldly;
using System.IO;
Expand All @@ -12,38 +13,38 @@ namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests.PackageRepositoryT
public class FileTests : TestBase
{
[Fact]
public void TextFileTest()
public void CustomFileTest()
{
const string relativePath = @"test\foo.txt";
const string contents = "FF6B25B727E04D9980DE3B5D7AE0FB6E";
const string contents = "798D159A4ADE45B9896EDE89FBA39C60";

FileInfo sourceFileInfo = new FileInfo(Path.Combine(TestRootPath, "something"));

File.WriteAllText(sourceFileInfo.FullName, contents);

PackageRepository.Create(TestRootPath)
.Package("PackageA", "1.0.0", out PackageIdentity packageA)
.FileText(relativePath, contents);
.FileCustom(relativePath, sourceFileInfo);

VerifyFileContents(packageA, relativePath, contents);
}

[Fact]
public void CustomFileTest()
public void TextFileTest()
{
const string relativePath = @"test\foo.txt";
const string contents = "798D159A4ADE45B9896EDE89FBA39C60";

FileInfo sourceFileInfo = new FileInfo(Path.Combine(TestRootPath, "something"));

File.WriteAllText(sourceFileInfo.FullName, contents);
const string contents = "FF6B25B727E04D9980DE3B5D7AE0FB6E";

PackageRepository.Create(TestRootPath)
.Package("PackageA", "1.0.0", out PackageIdentity packageA)
.FileCustom(relativePath, sourceFileInfo);
.FileText(relativePath, contents);

VerifyFileContents(packageA, relativePath, contents);
}

private void VerifyFileContents(PackageIdentity package, string relativePath, string contents)
{
DirectoryInfo packageDirectory = new DirectoryInfo(VersionFolderPathResolver.GetInstallPath(package.Id, package.Version))
DirectoryInfo packageDirectory = new DirectoryInfo(((VersionFolderPathResolver)VersionFolderPathResolver).GetInstallPath(package.Id, package.Version))
.ShouldExist();

FileInfo file = new FileInfo(Path.Combine(packageDirectory.FullName, relativePath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT license.

using NuGet.Frameworks;
using NuGet.Packaging;
using NuGet.Packaging.Core;
using Shouldly;
using System;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void MultipleLibrariesSameTargetFramework()

private void VerifyAssembly(PackageIdentity packageIdentity, NuGetFramework targetFramework, string assemblyFileName = null, string version = null)
{
DirectoryInfo packageDirectory = new DirectoryInfo(VersionFolderPathResolver.GetInstallPath(packageIdentity.Id, packageIdentity.Version))
DirectoryInfo packageDirectory = new DirectoryInfo(((VersionFolderPathResolver)VersionFolderPathResolver).GetInstallPath(packageIdentity.Id, packageIdentity.Version))
.ShouldExist();

DirectoryInfo libDirectory = new DirectoryInfo(Path.Combine(packageDirectory.FullName, "lib", targetFramework.GetShortFolderName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void BasicPackage()
package.Id.ShouldBe("PackageD");
package.Version.ShouldBe(NuGetVersion.Parse("1.2.3-beta"));

FileInfo manifestFilePath = new FileInfo(VersionFolderPathResolver.GetManifestFilePath(package.Id, package.Version))
FileInfo manifestFilePath = new FileInfo(((VersionFolderPathResolver)VersionFolderPathResolver).GetManifestFilePath(package.Id, package.Version))
.ShouldExist();

using (Stream stream = File.OpenRead(manifestFilePath.FullName))
Expand Down Expand Up @@ -78,7 +78,7 @@ public void CanSetAllPackageProperties()
package.Id.ShouldBe("PackageD");
package.Version.ShouldBe(NuGetVersion.Parse("1.2.3"));

FileInfo manifestFilePath = new FileInfo(VersionFolderPathResolver.GetManifestFilePath(package.Id, package.Version))
FileInfo manifestFilePath = new FileInfo(((VersionFolderPathResolver)VersionFolderPathResolver).GetManifestFilePath(package.Id, package.Version))
.ShouldExist();

using (Stream stream = File.OpenRead(manifestFilePath.FullName))
Expand Down
49 changes: 45 additions & 4 deletions src/MSBuildProjectCreator.UnitTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,47 @@
using NuGet.Packaging;
using System;
using System.IO;
using Xunit.Abstractions;

namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests
{
public abstract class TestBase : MSBuildTestBase, IDisposable
{
private readonly Lazy<VersionFolderPathResolver> _pathResolverLazy;
private readonly string _currentDirectoryBackup;

private readonly Lazy<object> _pathResolverLazy;

private readonly string _testRootPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

protected TestBase()
{
_pathResolverLazy = new Lazy<VersionFolderPathResolver>(() => new VersionFolderPathResolver(Path.Combine(TestRootPath, ".nuget", "packages")));
string globalJson = Path.Combine(TestRootPath, "global.json");
#if NETCOREAPP3_1
File.WriteAllText(
globalJson,
@"{
""sdk"": {
""version"": ""3.1.100"",
""rollForward"": ""latestFeature""
}
}");
#else
File.WriteAllText(
globalJson,
@"{
""sdk"": {
""version"": ""5.0.100"",
""rollForward"": ""latestMinor""
}
}");
#endif

// Save the current directory to restore it later
_currentDirectoryBackup = Environment.CurrentDirectory;

Environment.CurrentDirectory = TestRootPath;

_pathResolverLazy = new Lazy<object>(() => new VersionFolderPathResolver(Path.Combine(TestRootPath, ".nuget", "packages")));
}

public string TestRootPath
Expand All @@ -28,7 +57,7 @@ public string TestRootPath
}
}

public VersionFolderPathResolver VersionFolderPathResolver => _pathResolverLazy.Value;
public object VersionFolderPathResolver => _pathResolverLazy.Value;

public void Dispose()
{
Expand All @@ -40,9 +69,21 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (Directory.Exists(_currentDirectoryBackup))
{
Environment.CurrentDirectory = _currentDirectoryBackup;
}

if (Directory.Exists(TestRootPath))
{
Directory.Delete(TestRootPath, recursive: true);
try
{
Directory.Delete(TestRootPath, recursive: true);
}
catch (Exception)
{
// Ignored
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests
{
public static class TestOnlyExtensionMethods
internal static class TestOnlyExtensionMethods
{
public static ProjectCreator ForTestingOnly(this ProjectCreator creator, string param1, string param2)
{
Expand Down
Loading

0 comments on commit df3eb58

Please sign in to comment.