-
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 #489 from natidea/resolveFrameworkAssemblies
Add Framework Assemblies from project assets file to compiler references
- Loading branch information
Showing
8 changed files
with
277 additions
and
22 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...ets/TestProjects/AppsWithFrameworkReferences/EntityFrameworkApp/EntityFrameworkApp.csproj
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net451</TargetFramework> | ||
<RuntimeIdentifier>win7-x86</RuntimeIdentifier> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="**\*.cs" /> | ||
<EmbeddedResource Include="**\*.resx" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
23 changes: 23 additions & 0 deletions
23
TestAssets/TestProjects/AppsWithFrameworkReferences/EntityFrameworkApp/Program.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,23 @@ | ||
// 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. | ||
|
||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var b = new VerifyCodeViewModel | ||
{ | ||
Provider = "Required Test Provider" | ||
}; | ||
Console.WriteLine(b.Provider); | ||
} | ||
|
||
public class VerifyCodeViewModel | ||
{ | ||
[Required] | ||
public string Provider { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
TestAssets/TestProjects/AppsWithFrameworkReferences/StopwatchLib/Helper.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,15 @@ | ||
// 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. | ||
|
||
using System.Diagnostics; | ||
|
||
namespace StopwatchLib | ||
{ | ||
public static class Helper | ||
{ | ||
public static Stopwatch StartWatch() | ||
{ | ||
return Stopwatch.StartNew(); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
TestAssets/TestProjects/AppsWithFrameworkReferences/StopwatchLib/StopwatchLib.csproj
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net45</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="**\*.cs" /> | ||
<EmbeddedResource Include="**\*.resx" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NETStandard.Library" Version="1.6" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
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
153 changes: 153 additions & 0 deletions
153
test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAppsWithFrameworkRefs.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,153 @@ | ||
// 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. | ||
|
||
using FluentAssertions; | ||
using Microsoft.DotNet.Cli.Utils; | ||
using Microsoft.NET.TestFramework; | ||
using Microsoft.NET.TestFramework.Assertions; | ||
using Microsoft.NET.TestFramework.Commands; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Xml.Linq; | ||
using Xunit; | ||
using static Microsoft.NET.TestFramework.Commands.MSBuildTest; | ||
|
||
namespace Microsoft.NET.Build.Tests | ||
{ | ||
public class GivenThatWeWantToBuildAppsWithFrameworkRefs | ||
{ | ||
private TestAssetsManager _testAssetsManager = TestAssetsManager.TestProjectsAssetsManager; | ||
|
||
[Fact] | ||
public void It_builds_the_projects_successfully() | ||
{ | ||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
return; | ||
} | ||
|
||
var testAsset = _testAssetsManager | ||
.CopyTestAsset("AppsWithFrameworkReferences") | ||
.WithSource(); | ||
|
||
testAsset.Restore("EntityFrameworkApp"); | ||
testAsset.Restore("StopwatchLib"); | ||
|
||
VerifyProjectsBuild(testAsset); | ||
} | ||
|
||
[Fact] | ||
public void It_builds_with_disable_implicit_frameworkRefs() | ||
{ | ||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
return; | ||
} | ||
|
||
var testAsset = _testAssetsManager | ||
.CopyTestAsset("AppsWithFrameworkReferences") | ||
.WithSource(); | ||
|
||
testAsset.Restore("EntityFrameworkApp"); | ||
testAsset.Restore("StopwatchLib"); | ||
|
||
VerifyProjectsBuild(testAsset, "/p:DisableImplicitFrameworkReferences=true"); | ||
} | ||
|
||
void VerifyProjectsBuild(TestAsset testAsset, params string[] buildArgs) | ||
{ | ||
VerifyBuild(testAsset, "StopwatchLib", "net45", buildArgs, | ||
"StopwatchLib.dll", | ||
"StopwatchLib.pdb"); | ||
|
||
VerifyBuild(testAsset, "EntityFrameworkApp", "net451", buildArgs, | ||
"EntityFrameworkApp.exe", | ||
"EntityFrameworkApp.pdb", | ||
"EntityFrameworkApp.runtimeconfig.dev.json", | ||
"EntityFrameworkApp.runtimeconfig.json"); | ||
|
||
// Try running EntityFrameworkApp.exe | ||
var appProjectDirectory = Path.Combine(testAsset.TestRoot, "EntityFrameworkApp"); | ||
var buildCommand = new BuildCommand(Stage0MSBuild, appProjectDirectory); | ||
var outputDirectory = buildCommand.GetOutputDirectory("net451"); | ||
|
||
Command.Create(Path.Combine(outputDirectory.FullName, "EntityFrameworkApp.exe"), Enumerable.Empty<string>()) | ||
.CaptureStdOut() | ||
.Execute() | ||
.Should() | ||
.Pass() | ||
.And | ||
.HaveStdOutContaining("Required Test Provider"); | ||
} | ||
|
||
private void VerifyBuild(TestAsset testAsset, string project, string targetFramework, | ||
string [] buildArgs, | ||
params string [] expectedFiles) | ||
{ | ||
var appProjectDirectory = Path.Combine(testAsset.TestRoot, project); | ||
|
||
var buildCommand = new BuildCommand(Stage0MSBuild, appProjectDirectory); | ||
var outputDirectory = buildCommand.GetOutputDirectory(targetFramework); | ||
|
||
buildCommand | ||
.Execute(buildArgs) | ||
.Should() | ||
.Pass(); | ||
|
||
outputDirectory.Should().HaveFiles(expectedFiles); | ||
} | ||
|
||
[Fact] | ||
public void The_clean_target_removes_all_files_from_the_output_folder() | ||
{ | ||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
return; | ||
} | ||
|
||
var testAsset = _testAssetsManager | ||
.CopyTestAsset("AppsWithFrameworkReferences") | ||
.WithSource(); | ||
|
||
testAsset.Restore("EntityFrameworkApp"); | ||
testAsset.Restore("StopwatchLib"); | ||
|
||
VerifyClean(testAsset, "StopwatchLib", "net45", | ||
"StopwatchLib.dll", | ||
"StopwatchLib.pdb"); | ||
|
||
VerifyClean(testAsset, "EntityFrameworkApp", "net451", | ||
"EntityFrameworkApp.exe", | ||
"EntityFrameworkApp.pdb", | ||
"EntityFrameworkApp.runtimeconfig.dev.json", | ||
"EntityFrameworkApp.runtimeconfig.json"); | ||
} | ||
|
||
private void VerifyClean(TestAsset testAsset, string project, string targetFramework, | ||
params string[] expectedFiles) | ||
{ | ||
var appProjectDirectory = Path.Combine(testAsset.TestRoot, project); | ||
|
||
var buildCommand = new BuildCommand(Stage0MSBuild, appProjectDirectory); | ||
var outputDirectory = buildCommand.GetOutputDirectory(targetFramework); | ||
|
||
buildCommand | ||
.Execute() | ||
.Should() | ||
.Pass(); | ||
|
||
outputDirectory.Should().HaveFiles(expectedFiles); | ||
|
||
var cleanCommand = Stage0MSBuild.CreateCommandForTarget("Clean", buildCommand.FullPathProjectFile); | ||
|
||
cleanCommand | ||
.Execute() | ||
.Should() | ||
.Pass(); | ||
|
||
outputDirectory.Should().OnlyHaveFiles(Array.Empty<string>()); | ||
} | ||
} | ||
} |
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