提交 f313f4ba 编写于 作者: T TomasMatousek

Move facade references resolution to MetadataReferenceProvider and override it...

Move facade references resolution to MetadataReferenceProvider and override it in desktop implementation (MetadataFileReferenceProvider). (changeset 1275410)
上级 51ffaeeb
...@@ -1910,7 +1910,7 @@ internal class C ...@@ -1910,7 +1910,7 @@ internal class C
} }
[Fact] [Fact]
[WorkItem(531342, "DevDiv")] [WorkItem(531342, "DevDiv"), WorkItem(727122, "DevDiv")]
public void PortableLibrary() public void PortableLibrary()
{ {
var mscorlibPP7 = new MetadataImageReference(ProprietaryTestResources.NetFX.ReferenceAssemblies_PortableProfile7.mscorlib, display: "mscorlib, PP7"); var mscorlibPP7 = new MetadataImageReference(ProprietaryTestResources.NetFX.ReferenceAssemblies_PortableProfile7.mscorlib, display: "mscorlib, PP7");
...@@ -1932,7 +1932,7 @@ public void PortableLibrary() ...@@ -1932,7 +1932,7 @@ public void PortableLibrary()
// w/o facades: // w/o facades:
var main = CreateCompilation(mainSource, mainRefs); var main = CreateCompilation(mainSource, mainRefs, compOptions: TestOptions.Dll.WithMetadataReferenceProvider(MetadataFileReferenceProvider.Default));
main.VerifyDiagnostics( main.VerifyDiagnostics(
// (1,18): error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. // (1,18): error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Diagnostic(ErrorCode.ERR_NoTypeDef, "C").WithArguments("System.Object", "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")); Diagnostic(ErrorCode.ERR_NoTypeDef, "C").WithArguments("System.Object", "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"));
...@@ -1947,7 +1947,7 @@ public void PortableLibrary() ...@@ -1947,7 +1947,7 @@ public void PortableLibrary()
var facades = dir.CreateDirectory("Facades"); var facades = dir.CreateDirectory("Facades");
var systemRuntimeFacade = facades.CreateFile("System.Runtime.dll").WriteAllBytes(ProprietaryTestResources.NetFX.ReferenceAssemblies_V45_Facades.System_Runtime); var systemRuntimeFacade = facades.CreateFile("System.Runtime.dll").WriteAllBytes(ProprietaryTestResources.NetFX.ReferenceAssemblies_V45_Facades.System_Runtime);
main = CreateCompilation(mainSource, mainRefs); main = CreateCompilation(mainSource, mainRefs, compOptions: TestOptions.Dll.WithMetadataReferenceProvider(MetadataFileReferenceProvider.Default));
main.VerifyDiagnostics(); main.VerifyDiagnostics();
var expectedReferences = new string[] var expectedReferences = new string[]
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO; using System.Collections.Generic;
using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis namespace Microsoft.CodeAnalysis
{ {
...@@ -26,5 +26,11 @@ protected MetadataReferenceProvider() ...@@ -26,5 +26,11 @@ protected MetadataReferenceProvider()
/// <returns>A <see cref="PortableExecutableReference"/> corresponding to the <paramref name="resolvedPath"/> and /// <returns>A <see cref="PortableExecutableReference"/> corresponding to the <paramref name="resolvedPath"/> and
/// <paramref name="properties"/> parameters.</returns> /// <paramref name="properties"/> parameters.</returns>
public abstract PortableExecutableReference GetReference(string resolvedPath, MetadataReferenceProperties properties); public abstract PortableExecutableReference GetReference(string resolvedPath, MetadataReferenceProperties properties);
// TODO: workaround for bug #797360; remove
internal virtual IEnumerable<PortableExecutableReference> GetFacadeReferences(string mscorlibPath)
{
return SpecializedCollections.EmptyEnumerable<PortableExecutableReference>();
}
} }
} }
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.IO;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis namespace Microsoft.CodeAnalysis
{ {
/// <summary> /// <summary>
...@@ -24,5 +28,31 @@ public override PortableExecutableReference GetReference(string resolvedPath, Me ...@@ -24,5 +28,31 @@ public override PortableExecutableReference GetReference(string resolvedPath, Me
{ {
return new MetadataFileReference(resolvedPath, properties); return new MetadataFileReference(resolvedPath, properties);
} }
// TODO: workaround for bug #797360; remove
internal override IEnumerable<PortableExecutableReference> GetFacadeReferences(string mscorlibPath)
{
string facadesDirectory = PathUtilities.CombineAbsoluteAndRelativePaths(PathUtilities.GetDirectoryName(mscorlibPath), @"Facades");
string[] files;
if (!Directory.Exists(facadesDirectory))
{
yield break;
}
try
{
files = Directory.GetFiles(facadesDirectory, "*.dll", SearchOption.TopDirectoryOnly);
}
catch
{
yield break;
}
foreach (string file in files)
{
yield return new MetadataFileReference(file, MetadataReferenceProperties.Assembly);
}
}
} }
} }
...@@ -692,7 +692,10 @@ private static void AddModule(PEModule module, int referenceIndex, ResolvedRefer ...@@ -692,7 +692,10 @@ private static void AddModule(PEModule module, int referenceIndex, ResolvedRefer
} }
// Workaround for bug #797360: include facades if we reference a Portable Library: // Workaround for bug #797360: include facades if we reference a Portable Library:
if (compilation.Options.MetadataReferenceProvider != null)
{
referencesBuilder.AddRange(ResolveFacadeReferences(compilation)); referencesBuilder.AddRange(ResolveFacadeReferences(compilation));
}
// add external reference at the end, so that they are processed first: // add external reference at the end, so that they are processed first:
referencesBuilder.AddRange(compilation.ExternalReferences); referencesBuilder.AddRange(compilation.ExternalReferences);
...@@ -741,7 +744,7 @@ private IEnumerable<MetadataReference> ResolveFacadeReferences(TCompilation comp ...@@ -741,7 +744,7 @@ private IEnumerable<MetadataReference> ResolveFacadeReferences(TCompilation comp
return SpecializedCollections.EmptyEnumerable<MetadataReference>(); return SpecializedCollections.EmptyEnumerable<MetadataReference>();
} }
return GetFacadeReferences(mscorlibPath); return compilation.Options.MetadataReferenceProvider.GetFacadeReferences(mscorlibPath);
} }
private bool DetectPortableDependency(CompilationReference compilationReference, ref bool referencesPortableLibrary) private bool DetectPortableDependency(CompilationReference compilationReference, ref bool referencesPortableLibrary)
...@@ -819,31 +822,6 @@ private static bool HasSystemRuntime(ImmutableArray<AssemblyIdentity> identities ...@@ -819,31 +822,6 @@ private static bool HasSystemRuntime(ImmutableArray<AssemblyIdentity> identities
return false; return false;
} }
private static IEnumerable<MetadataReference> GetFacadeReferences(string mscorlibPath)
{
string facadesDirectory = PathUtilities.CombineAbsoluteAndRelativePaths(PathUtilities.GetDirectoryName(mscorlibPath), @"Facades");
string[] files;
if (!Directory.Exists(facadesDirectory))
{
yield break;
}
try
{
files = Directory.GetFiles(facadesDirectory, "*.dll", SearchOption.TopDirectoryOnly);
}
catch
{
yield break;
}
foreach (string file in files)
{
yield return new MetadataFileReference(file, MetadataReferenceProperties.Assembly);
}
}
private static bool IsMscorlib(AssemblyIdentity identity) private static bool IsMscorlib(AssemblyIdentity identity)
{ {
return string.Equals(identity.Name, "mscorlib", StringComparison.Ordinal) && ByteSequenceComparer.Instance.Equals(identity.PublicKeyToken, MscorlibPublicKeyToken); return string.Equals(identity.Name, "mscorlib", StringComparison.Ordinal) && ByteSequenceComparer.Instance.Equals(identity.PublicKeyToken, MscorlibPublicKeyToken);
......
...@@ -29,7 +29,8 @@ public MetadataReferenceProvider GetProvider() ...@@ -29,7 +29,8 @@ public MetadataReferenceProvider GetProvider()
} }
} }
private sealed class Provider : MetadataReferenceProvider // TODO: inherit directly from MetadataReferenceProvider when bug #797360 is fixed
private sealed class Provider : MetadataFileReferenceProvider
{ {
private readonly IDocumentationProviderService documentationService; private readonly IDocumentationProviderService documentationService;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册