-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MSLukeWest/MSLukeWest-NetCorePublishItemsO…
…utputGroup Adding NetCorePublishItemsOutputGroup to support VS installer project scenarios
- Loading branch information
Showing
4 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/Tests/Microsoft.NET.Publish.Tests/NetCorePublishItemsOutputGroupTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using FluentAssertions; | ||
using Microsoft.NET.TestFramework; | ||
using Microsoft.NET.TestFramework.Assertions; | ||
using Microsoft.NET.TestFramework.Commands; | ||
using Microsoft.NET.TestFramework.ProjectConstruction; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.NET.Publish.Tests | ||
{ | ||
public class NetCorePublishItemsOutputGroupTests : SdkTest | ||
{ | ||
public NetCorePublishItemsOutputGroupTests(ITestOutputHelper log) : base(log) | ||
{ | ||
} | ||
|
||
private static List<string> FrameworkAssemblies = new List<string>() | ||
{ | ||
"api-ms-win-core-console-l1-1-0.dll", | ||
"System.Runtime.dll", | ||
"WindowsBase.dll", | ||
}; | ||
|
||
[CoreMSBuildOnlyFact] | ||
public void GroupPopulatedWithRid() | ||
{ | ||
var testProject = this.SetupProject(); | ||
var testAsset = _testAssetsManager.CreateTestProject(testProject); | ||
|
||
var restoreCommand = new RestoreCommand(Log, testAsset.Path, testProject.Name); | ||
restoreCommand | ||
.Execute() | ||
.Should() | ||
.Pass(); | ||
|
||
var buildCommand = new BuildCommand(Log, testAsset.Path, testProject.Name); | ||
buildCommand | ||
.Execute("/p:RuntimeIdentifier=win-x86", "/t:NetCorePublishItemsOutputGroup") | ||
.Should() | ||
.Pass(); | ||
|
||
var testOutputDir = Path.Combine(testAsset.Path, testProject.Name, "TestOutput"); | ||
Log.WriteLine("Contents of NetCorePublishItemsOutputGroup dumped to '{0}'.", testOutputDir); | ||
|
||
// Check for the existence of a few specific files that should be in the directory where the | ||
// contents of NetCorePublishItemsOutputGroup were dumped to make sure it's getting populated. | ||
Assert.True(File.Exists(Path.Combine(testOutputDir, $"{testProject.Name}.exe")), $"Assembly {testProject.Name}.exe is present in the output group."); | ||
foreach (var assem in FrameworkAssemblies) | ||
{ | ||
Assert.True(File.Exists(Path.Combine(testOutputDir, assem)), $"Assembly {assem} is present in the output group."); | ||
} | ||
} | ||
|
||
[CoreMSBuildOnlyFact] | ||
public void GroupNotPopulatedWithoutRid() | ||
{ | ||
var testProject = this.SetupProject(); | ||
var testAsset = _testAssetsManager.CreateTestProject(testProject); | ||
|
||
var restoreCommand = new RestoreCommand(Log, testAsset.Path, testProject.Name); | ||
restoreCommand | ||
.Execute() | ||
.Should() | ||
.Pass(); | ||
|
||
var buildCommand = new BuildCommand(Log, testAsset.Path, testProject.Name); | ||
buildCommand | ||
.Execute("/t:NetCorePublishItemsOutputGroup") | ||
.Should() | ||
.Pass(); | ||
|
||
var testOutputDir = Path.Combine(testAsset.Path, testProject.Name, "TestOutput"); | ||
Log.WriteLine("Contents of NetCorePublishItemsOutputGroup dumped to '{0}'.", testOutputDir); | ||
|
||
// Since no RID was specified the output group should only contain framework dependent output | ||
Assert.True(File.Exists(Path.Combine(testOutputDir, $"{testProject.Name}.exe")), $"Assembly {testProject.Name}.exe is present in the output group."); | ||
foreach (var assem in FrameworkAssemblies) | ||
{ | ||
Assert.False(File.Exists(Path.Combine(testOutputDir, assem)), $"Assembly {assem} is not present in the output group."); | ||
} | ||
} | ||
|
||
private TestProject SetupProject() | ||
{ | ||
var testProject = new TestProject() | ||
{ | ||
Name = "TestPublishOutputGroup", | ||
TargetFrameworks = "netcoreapp3.0", | ||
IsSdkProject = true, | ||
IsExe = true | ||
}; | ||
|
||
testProject.AdditionalProperties["RuntimeIdentifiers"] = "win-x86"; | ||
|
||
// Use a test-specific packages folder | ||
testProject.AdditionalProperties["RestorePackagesPath"] = @"$(MSBuildProjectDirectory)\..\pkg"; | ||
|
||
// Add a target that will dump the contents of the NetCorePublishItemsOutputGroup to | ||
// a test directory after building. | ||
testProject.CopyFilesTargets.Add(new CopyFilesTarget( | ||
"CopyNetCorePublishItemsOutputGroup", | ||
"NetCorePublishItemsOutputGroup", | ||
"@(NetCorePublishItemsOutputGroupOutputs)", | ||
"$(MSBuildProjectDirectory)\\TestOutput")); | ||
|
||
return testProject; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.NET.TestFramework | ||
{ | ||
/// <summary> | ||
/// Represents a target that will copy some set of files to a given location after some other target completes. | ||
/// Useful for verifying the contents of an output group in a test. | ||
/// </summary> | ||
public class CopyFilesTarget | ||
{ | ||
public CopyFilesTarget(string targetName, string targetToRunAfter, string sourceFiles, string destination) | ||
{ | ||
TargetName = targetName; | ||
TargetToRunAfter = targetToRunAfter; | ||
SourceFiles = sourceFiles; | ||
Destination = destination; | ||
} | ||
|
||
public string TargetName { get; private set; } | ||
public string TargetToRunAfter { get; private set; } | ||
public string SourceFiles { get; private set; } | ||
public string Destination { get; private set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters