-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Framework Assemblies from project assets file to compiler references #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
35049cf
Add Framework Assemblies raised from project assets file to compiler …
natidea f12c3b1
Add tests for apps with Framework References
natidea cd2ac0a
Disable tests referencing .NET Framework on Linux
natidea c4cd28a
Pass DisableImplicitFrameworkReferences and DisableLockFileFrameworks…
natidea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...ets/TestProjects/AppsWithFrameworkReferences/EntityFrameworkApp/EntityFrameworkApp.csproj
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -361,6 +361,12 @@ private void GetFileDependencies(LockFileTargetLibrary package, string targetNam | |
item.SetMetadata(MetadataKeys.ParentTarget, targetName); // Foreign Key | ||
item.SetMetadata(MetadataKeys.ParentPackage, packageId); // Foreign Key | ||
|
||
if (fileGroup == FileGroup.FrameworkAssembly) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be helpful to have a comment here explaining how the FrameworkAssembly reference is expressed in the lockfile. From the code I gather that it has a path which instead of referring to a file in the package is just the name of the framework reference to add. |
||
{ | ||
// NOTE: the path provided for framework assemblies is the name of the framework reference | ||
item.SetMetadata("FrameworkAssembly", filePath); | ||
} | ||
|
||
foreach (var property in properties) | ||
{ | ||
item.SetMetadata(property.Key, property.Value); | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this have a reference to Microsoft.NETCore.App until #450 is merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for the case where the SDK is not present? I would have expected
Project Sdk="Microsoft.NET.Sdk"
to be sufficient here, and it appears to work on all my test machines.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NerCore.App is needed for netcore projects (even if the SDK is present). This is however a Desktop project - so not needed here.