Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 62 additions & 15 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ variables:
ArtifactsDirectoryName: 'artifacts'
BuildConfiguration: 'Debug'
BuildPlatform: 'Any CPU'
DotNetCore3Version: '3.x'
DotNet5Version: '5.x'
MSBuildArgs: '"/p:Platform=$(BuildPlatform)" "/p:Configuration=$(BuildConfiguration)" "/BinaryLogger:$(Build.SourcesDirectory)\$(ArtifactsDirectoryName)\msbuild.binlog"'

Expand All @@ -29,16 +28,11 @@ pr:
- '*.md'

jobs:
- job: BuildAndTest
displayName: 'Build and Test'
- job: WindowsBuild
displayName: 'Build and Test (Windows)'
pool:
vmImage: windows-latest
steps:
- task: UseDotNet@2
displayName: 'Install .NET Core $(DotNetCore3Version)'
inputs:
version: '$(DotNetCore3Version)'

- task: UseDotNet@2
displayName: 'Install .NET $(DotNet5Version)'
inputs:
Expand All @@ -56,27 +50,80 @@ jobs:
inputs:
command: 'test'
arguments: '--no-restore --no-build --framework net5.0 "/restore:false"'
testRunTitle: '.NET 5.0'
testRunTitle: 'Windows .NET 5.0'

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

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
PathtoPublish: '$(ArtifactsDirectoryName)'
ArtifactName: '$(ArtifactsDirectoryName)-win'
condition: always()

- job: LinuxBuild
displayName: 'Build and Test (Linux)'
pool:
vmImage: ubuntu-latest
steps:
- task: UseDotNet@2
displayName: 'Install .NET Core $(DotNet5Version)'
inputs:
version: '$(DotNet5Version)'

- task: DotNetCoreCLI@2
displayName: 'Run Unit Tests (.NET Core)'
condition: succeededOrFailed()
displayName: 'dotnet build'
inputs:
command: 'build'
arguments: '$(MSBuildArgs)'

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

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
PathtoPublish: '$(ArtifactsDirectoryName)'
ArtifactName: '$(ArtifactsDirectoryName)-linux'
condition: always()

- job: MacOSBuild
displayName: 'Build and Test (Mac)'
pool:
vmImage: macOS-latest
steps:
- task: UseDotNet@2
displayName: 'Install .NET Core $(DotNet5Version)'
inputs:
version: '$(DotNet5Version)'

- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
command: 'build'
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: 'MacOS .NET 5.0'


- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
PathtoPublish: '$(ArtifactsDirectoryName)'
ArtifactName: $(ArtifactsDirectoryName)
ArtifactName: '$(ArtifactsDirectoryName)-macOS'
condition: always()
7 changes: 4 additions & 3 deletions src/MSBuildProjectCreator.UnitTests/BuildOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Shouldly;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Xunit;

Expand Down Expand Up @@ -96,9 +97,9 @@ public void ResultsByProject()
{
Dictionary<string, bool> projects = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase)
{
{ @"DA920698\E40D\4D8F\89D8\B85D870C4214", true },
{ @"53C78698\F360\491F\8025\B323782DD912", false },
{ @"F42234CB\7504\4F23\ACD7\D58F5BCDD3C6", true },
{ Path.Combine("DA920698", "E40D", "4D8F", "89D8", "B85D870C4214"), true },
{ Path.Combine("53C78698", "F360", "491F", "8025", "B323782DD912"), false },
{ Path.Combine("F42234CB", "7504", "4F23", "ACD7", "D58F5BCDD3C6"), true },
};

BuildOutput buildOutput = GetProjectLoggerWithEvents(eventSource => { Parallel.ForEach(projects, project => { eventSource.OnProjectFinished(project.Key, project.Value); }); });
Expand Down
31 changes: 13 additions & 18 deletions src/MSBuildProjectCreator.UnitTests/BuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,20 @@ public class BuildTests : TestBase
[Fact]
public void BuildCanConsumePackage()
{
Action t = () =>
{
PackageRepository packageRepository = PackageRepository.Create(TestRootPath)
.Package("PackageB", "1.0", out PackageIdentity packageB)
.Library("net45")
.Package("PackageA", "1.0.0", out PackageIdentity packageA)
.Dependency(packageB, "net45")
.Library("net45");

ProjectCreator.Templates.SdkCsproj(
targetFramework: "net45")
.ItemPackageReference(packageA)
.Save(Path.Combine(TestRootPath, "ClassLibraryA", "ClassLibraryA.csproj"))
.TryBuild(restore: true, out bool result, out BuildOutput buildOutput);
PackageRepository packageRepository = PackageRepository.Create(TestRootPath)
.Package("PackageB", "1.0", out PackageIdentity packageB)
.Library("net45")
.Package("PackageA", "1.0.0", out PackageIdentity packageA)
.Dependency(packageB, "net45")
.Library("net45");

ProjectCreator.Templates.SdkCsproj(
targetFramework: "net45")
.ItemPackageReference(packageA)
.Save(Path.Combine(TestRootPath, "ClassLibraryA", "ClassLibraryA.csproj"))
.TryBuild(restore: true, out bool result, out BuildOutput buildOutput);

result.ShouldBeTrue(buildOutput.GetConsoleLog());
};

t.Invoke();
result.ShouldBeTrue(buildOutput.GetConsoleLog());
}

[Fact]
Expand Down
3 changes: 2 additions & 1 deletion src/MSBuildProjectCreator.UnitTests/ExperimentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Microsoft.Build.Framework;
using System.Collections.Generic;
using System.IO;
using Xunit;

namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests
Expand All @@ -24,7 +25,7 @@ public void Experiment1()
projectCreator
.ItemGroup()
.ItemCompile("Class1.cs")
.ItemCompile(@"Properties\AssemblyInfo.cs")
.ItemCompile(Path.Combine("Properties", "AssemblyInfo.cs"))
.ItemGroup()
.ItemNone("App.config", metadata: new Dictionary<string, string> { { "SubType", "Designer" } });
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>net472;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.Frameworks" />
<PackageReference Include="NuGet.Packaging" />
<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 @@ -74,8 +74,8 @@ public void BuildMultiTargetingTest()
.BuildMultiTargetingProps(out ProjectCreator buildMultiTargetingPropsProject)
.BuildMultiTargetingTargets(out ProjectCreator buildMultiTargetingTargetsProject);

buildMultiTargetingPropsProject.FullPath.ShouldBe($@"{TestRootPath}\.nuget\packages\packagea\2.0.0\buildMultiTargeting\PackageA.props");
buildMultiTargetingTargetsProject.FullPath.ShouldBe($@"{TestRootPath}\.nuget\packages\packagea\2.0.0\buildMultiTargeting\PackageA.targets");
buildMultiTargetingPropsProject.FullPath.ShouldBe(Path.Combine(TestRootPath, ".nuget", "packages", "packagea", "2.0.0", "buildMultiTargeting", "PackageA.props"));
buildMultiTargetingTargetsProject.FullPath.ShouldBe(Path.Combine(TestRootPath, ".nuget", "packages", "packagea", "2.0.0", "buildMultiTargeting", "PackageA.targets"));

File.Exists(buildMultiTargetingPropsProject.FullPath).ShouldBeTrue();
File.Exists(buildMultiTargetingTargetsProject.FullPath).ShouldBeTrue();
Expand All @@ -89,8 +89,8 @@ public void BuildPropsTest()
.BuildProps(out ProjectCreator buildPropsProject)
.BuildTargets(out ProjectCreator buildTargetsProject);

buildPropsProject.FullPath.ShouldBe($@"{TestRootPath}\.nuget\packages\packagea\2.0.0\build\PackageA.props");
buildTargetsProject.FullPath.ShouldBe($@"{TestRootPath}\.nuget\packages\packagea\2.0.0\build\PackageA.targets");
buildPropsProject.FullPath.ShouldBe(Path.Combine(TestRootPath, ".nuget", "packages", "packagea", "2.0.0", "build", "PackageA.props"));
buildTargetsProject.FullPath.ShouldBe(Path.Combine(TestRootPath, ".nuget", "packages", "packagea", "2.0.0", "build", "PackageA.targets"));

File.Exists(buildPropsProject.FullPath).ShouldBeTrue();
File.Exists(buildTargetsProject.FullPath).ShouldBeTrue();
Expand All @@ -104,8 +104,8 @@ public void BuildTransitiveTest()
.BuildTransitiveProps(out ProjectCreator buildTransitivePropsProject)
.BuildTransitiveTargets(out ProjectCreator buildTransitiveTargetsProject);

buildTransitivePropsProject.FullPath.ShouldBe($@"{TestRootPath}\.nuget\packages\packagea\2.0.0\buildTransitive\PackageA.props");
buildTransitiveTargetsProject.FullPath.ShouldBe($@"{TestRootPath}\.nuget\packages\packagea\2.0.0\buildTransitive\PackageA.targets");
buildTransitivePropsProject.FullPath.ShouldBe(Path.Combine(TestRootPath, ".nuget", "packages", "packagea", "2.0.0", "buildTransitive", "PackageA.props"));
buildTransitiveTargetsProject.FullPath.ShouldBe(Path.Combine(TestRootPath, ".nuget", "packages", "packagea", "2.0.0", "buildTransitive", "PackageA.targets"));

File.Exists(buildTransitivePropsProject.FullPath).ShouldBeTrue();
File.Exists(buildTransitiveTargetsProject.FullPath).ShouldBeTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class FileTests : TestBase
[Fact]
public void CustomFileTest()
{
const string relativePath = @"test\foo.txt";
string relativePath = Path.Combine("test", "foo.txt");
const string contents = "798D159A4ADE45B9896EDE89FBA39C60";

FileInfo sourceFileInfo = new FileInfo(Path.Combine(TestRootPath, "something"));
Expand All @@ -32,7 +32,7 @@ public void CustomFileTest()
[Fact]
public void TextFileTest()
{
const string relativePath = @"test\foo.txt";
string relativePath = Path.Combine("test", "foo.txt");
const string contents = "FF6B25B727E04D9980DE3B5D7AE0FB6E";

PackageRepository.Create(TestRootPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void CanSetAllPackageProperties()
copyright: "Copyright 2000",
developmentDependency: true,
#if !NET46
icon: @"some\icon.jpg",
icon: Path.Combine("some", "icon.jpg"),
#endif
iconUrl: "https://icon.url",
language: "Pig latin",
Expand Down Expand Up @@ -90,7 +90,7 @@ public void CanSetAllPackageProperties()
manifest.Metadata.Description.ShouldBe("Custom description");
manifest.Metadata.DevelopmentDependency.ShouldBeTrue();
#if !NET46
manifest.Metadata.Icon.ShouldBe(@"some\icon.jpg");
manifest.Metadata.Icon.ShouldBe(Path.Combine("some", "icon.jpg"));
#endif
manifest.Metadata.IconUrl.ShouldBe(new Uri("https://icon.url"));
manifest.Metadata.Id.ShouldBe("PackageD");
Expand Down
26 changes: 3 additions & 23 deletions src/MSBuildProjectCreator.UnitTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using NuGet.Packaging;
using System;
using System.IO;
using Xunit.Abstractions;

namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests
{
Expand All @@ -15,30 +14,18 @@ public abstract class TestBase : MSBuildTestBase, IDisposable

private readonly Lazy<object> _pathResolverLazy;

private readonly string _testRootPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
private readonly Lazy<string> _testRootPathLazy = new Lazy<string>(() => Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())).FullName);

protected TestBase()
{
string globalJson = Path.Combine(TestRootPath, "global.json");
#if NETCOREAPP3_1
File.WriteAllText(
globalJson,
@"{
""sdk"": {
""version"": ""3.1.100"",
""rollForward"": ""latestFeature""
}
}");
#else
File.WriteAllText(
globalJson,
Path.Combine(TestRootPath, "global.json"),
@"{
""sdk"": {
""version"": ""5.0.100"",
""rollForward"": ""latestMinor""
}
}");
#endif
File.WriteAllText(
Path.Combine(TestRootPath, "NuGet.config"),
@"<?xml version=""1.0"" encoding=""utf-8""?>
Expand All @@ -57,14 +44,7 @@ protected TestBase()
_pathResolverLazy = new Lazy<object>(() => new VersionFolderPathResolver(Path.Combine(TestRootPath, ".nuget", "packages")));
}

public string TestRootPath
{
get
{
Directory.CreateDirectory(_testRootPath);
return _testRootPath;
}
}
public string TestRootPath => _testRootPathLazy.Value;

public object VersionFolderPathResolver => _pathResolverLazy.Value;

Expand Down
14 changes: 7 additions & 7 deletions src/MSBuildProjectCreator/MSBuildAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
// Licensed under the MIT license.

using System;
#if NETCORE
#if !NETFRAMEWORK
using System.Diagnostics;
#endif
using System.IO;
using System.Linq;
using System.Reflection;
#if NETCORE
#if !NETFRAMEWORK
using System.Text.RegularExpressions;
using System.Threading;
#endif
#if !NETCORE
#if NETFRAMEWORK
using Microsoft.VisualStudio.Setup.Configuration;
#endif

Expand All @@ -27,7 +27,7 @@ public static class MSBuildAssemblyResolver
private static readonly Lazy<string[]> MSBuildDirectoryLazy = new Lazy<string[]>(
() =>
{
#if NETCORE
#if !NETFRAMEWORK
string basePath = GetDotNetBasePath();

if (!string.IsNullOrWhiteSpace(basePath))
Expand Down Expand Up @@ -85,7 +85,7 @@ public static class MSBuildAssemblyResolver

private static readonly string[] AssemblyExtensions = { ".dll", ".exe" };

#if NETCORE
#if !NETFRAMEWORK
private static readonly Regex DotNetBasePathRegex = new Regex(@"^ Base Path:\s+(?<Path>.*)$");
#endif

Expand Down Expand Up @@ -136,7 +136,7 @@ public static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
return null;
}

#if NETCORE
#if !NETFRAMEWORK

private static string GetDotNetBasePath()
{
Expand Down Expand Up @@ -231,7 +231,7 @@ private static string GetMSBuildVersionDirectory(string version)
return version;
}

#if !NETCORE
#if NETFRAMEWORK

private static string GetPathOfFirstInstalledVisualStudioInstance()
{
Expand Down
Loading