dotnet build raises errors MVC apps target net46.
The issue is when the ProjectContextBuilder sees a CompileTimePlaceholder "_._" file on a full framework, it assumes that dependency has to come from the "Reference Assemblies" directory. If it can't be found there, an error is raised. However, there are other reasons "_._" placeholders are created (when a NuGet package doesn't want its dependencies to be exposed in the Compile dependencies of its consumers). And these placeholders can exist for assemblies that aren't in the full framework - in this case System.Diagnostics.FileVersionInfo and others. To fix this, if the reference can't be resolved from the "Reference Assemblies" folder, it is just skipped. If the compiler really needs that assembly, it will raise an error to the user. Dotnet build shouldn't raise the error. Fix #2906
This commit is contained in:
parent
3b2ea9d14b
commit
d98c1f8724
5 changed files with 49 additions and 6 deletions
|
@ -0,0 +1 @@
|
|||
noautobuild
|
10
TestAssets/TestProjects/AppWithNet46AndRoslyn/Program.cs
Normal file
10
TestAssets/TestProjects/AppWithNet46AndRoslyn/Program.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace AppWithNet46AndRoslyn
|
||||
{
|
||||
public class MyApp
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
System.Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
}
|
11
TestAssets/TestProjects/AppWithNet46AndRoslyn/project.json
Normal file
11
TestAssets/TestProjects/AppWithNet46AndRoslyn/project.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"buildOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.CodeAnalysis.CSharp": "1.3.0-beta1-20160429-01"
|
||||
},
|
||||
"frameworks": {
|
||||
"net46": { }
|
||||
}
|
||||
}
|
|
@ -440,15 +440,21 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
package.HasCompileTimePlaceholder &&
|
||||
!TargetFramework.IsPackageBased)
|
||||
{
|
||||
// requiresFrameworkAssemblies is true whenever we find a CompileTimePlaceholder in a non-package based framework, even if
|
||||
// the reference is unresolved. This ensures the best error experience when someone is building on a machine without
|
||||
// the target framework installed.
|
||||
requiresFrameworkAssemblies = true;
|
||||
|
||||
var newKey = new LibraryKey(library.Identity.Name, LibraryType.ReferenceAssembly);
|
||||
var dependency = new LibraryRange(library.Identity.Name, LibraryType.ReferenceAssembly);
|
||||
|
||||
// If the framework assembly can't be resolved then mark it as unresolved but still replace the package
|
||||
// dependency
|
||||
var replacement = referenceAssemblyDependencyResolver.GetDescription(dependency, TargetFramework) ??
|
||||
UnresolvedDependencyProvider.GetDescription(dependency, TargetFramework);
|
||||
|
||||
requiresFrameworkAssemblies = true;
|
||||
var replacement = referenceAssemblyDependencyResolver.GetDescription(dependency, TargetFramework);
|
||||
|
||||
// If the reference is unresolved, just skip it. Don't replace the package dependency
|
||||
if (replacement == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove the original package reference
|
||||
libraries.Remove(pair.Key);
|
||||
|
|
|
@ -100,5 +100,20 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
"TestLibraryWithXmlDoc.xml"
|
||||
});
|
||||
}
|
||||
|
||||
[WindowsOnlyFact]
|
||||
public void It_builds_projects_targeting_net46_and_Roslyn()
|
||||
{
|
||||
var testInstance = TestAssetsManager
|
||||
.CreateTestInstance("AppWithNet46AndRoslyn")
|
||||
.WithLockFiles();
|
||||
|
||||
var testProject = Path.Combine(testInstance.TestRoot, "project.json");
|
||||
|
||||
new BuildCommand(testProject)
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue