diff --git a/src/Microsoft.CodeAnalysis.Razor/Properties/ViewComponentResources.Designer.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/Properties/ViewComponentResources.Designer.cs
similarity index 98%
rename from src/Microsoft.CodeAnalysis.Razor/Properties/ViewComponentResources.Designer.cs
rename to src/Microsoft.AspNetCore.Mvc.Razor.Extensions/Properties/ViewComponentResources.Designer.cs
index 343bd246be..6813fb723b 100644
--- a/src/Microsoft.CodeAnalysis.Razor/Properties/ViewComponentResources.Designer.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/Properties/ViewComponentResources.Designer.cs
@@ -1,5 +1,5 @@
//
-namespace Microsoft.CodeAnalysis.Razor
+namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
using System.Globalization;
using System.Reflection;
diff --git a/src/Microsoft.CodeAnalysis.Razor/ViewComponentDiagnosticFactory.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentDiagnosticFactory.cs
similarity index 98%
rename from src/Microsoft.CodeAnalysis.Razor/ViewComponentDiagnosticFactory.cs
rename to src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentDiagnosticFactory.cs
index dacfec538a..0584cd78d4 100644
--- a/src/Microsoft.CodeAnalysis.Razor/ViewComponentDiagnosticFactory.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentDiagnosticFactory.cs
@@ -4,7 +4,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
-namespace Microsoft.CodeAnalysis.Razor
+namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
internal class ViewComponentDiagnosticFactory
{
diff --git a/src/Microsoft.CodeAnalysis.Razor/ViewComponentResources.resx b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentResources.resx
similarity index 100%
rename from src/Microsoft.CodeAnalysis.Razor/ViewComponentResources.resx
rename to src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentResources.resx
diff --git a/src/Microsoft.CodeAnalysis.Razor/ViewComponentTagHelperDescriptorConventions.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorConventions.cs
similarity index 95%
rename from src/Microsoft.CodeAnalysis.Razor/ViewComponentTagHelperDescriptorConventions.cs
rename to src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorConventions.cs
index 794b7bcab1..63bb660c65 100644
--- a/src/Microsoft.CodeAnalysis.Razor/ViewComponentTagHelperDescriptorConventions.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorConventions.cs
@@ -3,7 +3,7 @@
using Microsoft.AspNetCore.Razor.Language;
-namespace Microsoft.CodeAnalysis.Razor
+namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
///
/// A library of methods used to generate s for view components.
diff --git a/src/Microsoft.CodeAnalysis.Razor/ViewComponentTagHelperDescriptorFactory.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorFactory.cs
similarity index 99%
rename from src/Microsoft.CodeAnalysis.Razor/ViewComponentTagHelperDescriptorFactory.cs
rename to src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorFactory.cs
index 8c6392dfc9..7bc925d292 100644
--- a/src/Microsoft.CodeAnalysis.Razor/ViewComponentTagHelperDescriptorFactory.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorFactory.cs
@@ -6,8 +6,9 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.AspNetCore.Razor.Language;
+using Microsoft.CodeAnalysis;
-namespace Microsoft.CodeAnalysis.Razor
+namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
internal class ViewComponentTagHelperDescriptorFactory
{
diff --git a/src/Microsoft.CodeAnalysis.Razor/ViewComponentTagHelperDescriptorProvider.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorProvider.cs
similarity index 94%
rename from src/Microsoft.CodeAnalysis.Razor/ViewComponentTagHelperDescriptorProvider.cs
rename to src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorProvider.cs
index 52e2dedc39..10150c3e80 100644
--- a/src/Microsoft.CodeAnalysis.Razor/ViewComponentTagHelperDescriptorProvider.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTagHelperDescriptorProvider.cs
@@ -4,8 +4,10 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.Razor;
-namespace Microsoft.CodeAnalysis.Razor
+namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
public sealed class ViewComponentTagHelperDescriptorProvider : RazorEngineFeatureBase, ITagHelperDescriptorProvider
{
diff --git a/src/Microsoft.CodeAnalysis.Razor/ViewComponentTypeVisitor.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTypeVisitor.cs
similarity index 97%
rename from src/Microsoft.CodeAnalysis.Razor/ViewComponentTypeVisitor.cs
rename to src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTypeVisitor.cs
index 8dda01d30b..c26779a9c5 100644
--- a/src/Microsoft.CodeAnalysis.Razor/ViewComponentTypeVisitor.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTypeVisitor.cs
@@ -4,8 +4,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Microsoft.CodeAnalysis;
-namespace Microsoft.CodeAnalysis.Razor
+namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
internal class ViewComponentTypeVisitor : SymbolVisitor
{
diff --git a/src/Microsoft.CodeAnalysis.Razor/ViewComponentTypes.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTypes.cs
similarity index 95%
rename from src/Microsoft.CodeAnalysis.Razor/ViewComponentTypes.cs
rename to src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTypes.cs
index b48dad9c41..2fab7878fa 100644
--- a/src/Microsoft.CodeAnalysis.Razor/ViewComponentTypes.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ViewComponentTypes.cs
@@ -3,7 +3,7 @@
using System;
-namespace Microsoft.CodeAnalysis.Razor
+namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
internal static class ViewComponentTypes
{
diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj b/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj
index 0738c692a0..ca0b25a90b 100644
--- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj
+++ b/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj
@@ -11,6 +11,5 @@
-
diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs b/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs
index 175ea48620..a16f46400b 100644
--- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs
+++ b/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. 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.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultTagHelperResolver.cs b/src/Microsoft.CodeAnalysis.Remote.Razor/DefaultTagHelperResolver.cs
similarity index 90%
rename from src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultTagHelperResolver.cs
rename to src/Microsoft.CodeAnalysis.Remote.Razor/DefaultTagHelperResolver.cs
index df4f40cbdb..30e1c638e4 100644
--- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultTagHelperResolver.cs
+++ b/src/Microsoft.CodeAnalysis.Remote.Razor/DefaultTagHelperResolver.cs
@@ -2,9 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
+using Microsoft.AspNetCore.Mvc.Razor.Extensions;
using Microsoft.AspNetCore.Razor.Language;
+using Microsoft.CodeAnalysis.Razor;
-namespace Microsoft.CodeAnalysis.Razor
+namespace Microsoft.CodeAnalysis.Remote.Razor
{
internal class DefaultTagHelperResolver : TagHelperResolver
{
@@ -21,7 +23,7 @@ namespace Microsoft.CodeAnalysis.Razor
var providers = new ITagHelperDescriptorProvider[]
{
- new DefaultTagHelperDescriptorProvider() { DesignTime = true, },
+ new DefaultTagHelperDescriptorProvider() { DesignTime = DesignTime, },
new ViewComponentTagHelperDescriptorProvider(),
};
diff --git a/src/Microsoft.CodeAnalysis.Remote.Razor/Microsoft.CodeAnalysis.Remote.Razor.csproj b/src/Microsoft.CodeAnalysis.Remote.Razor/Microsoft.CodeAnalysis.Remote.Razor.csproj
index 778c7388ca..ea34738c7c 100644
--- a/src/Microsoft.CodeAnalysis.Remote.Razor/Microsoft.CodeAnalysis.Remote.Razor.csproj
+++ b/src/Microsoft.CodeAnalysis.Remote.Razor/Microsoft.CodeAnalysis.Remote.Razor.csproj
@@ -19,5 +19,6 @@
+
diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs
index 4b03ed2dec..22804f9b90 100644
--- a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs
+++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs
@@ -6,6 +6,8 @@ using System.Collections.Generic;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc.Razor.Extensions;
+using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Shell;
@@ -56,8 +58,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
}
// The OOP host is turned off, so let's do this in process.
- var resolver = new CodeAnalysis.Razor.DefaultTagHelperResolver(designTime: true);
- result = await resolver.GetTagHelpersAsync(project, CancellationToken.None).ConfigureAwait(false);
+ var compilation = await project.GetCompilationAsync(CancellationToken.None).ConfigureAwait(false);
+ result = GetTagHelpers(compilation, designTime: true);
return result;
}
catch (Exception exception)
@@ -79,6 +81,32 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
}
}
+ private TagHelperResolutionResult GetTagHelpers(Compilation compilation, bool designTime)
+ {
+ var descriptors = new List();
+
+ var providers = new ITagHelperDescriptorProvider[]
+ {
+ new DefaultTagHelperDescriptorProvider() { DesignTime = designTime, },
+ new ViewComponentTagHelperDescriptorProvider(),
+ };
+
+ var results = new List();
+ var context = TagHelperDescriptorProviderContext.Create(results);
+ context.SetCompilation(compilation);
+
+ for (var i = 0; i < providers.Length; i++)
+ {
+ var provider = providers[i];
+ provider.Execute(context);
+ }
+
+ var diagnostics = new List();
+ var resolutionResult = new TagHelperResolutionResult(results, diagnostics);
+
+ return resolutionResult;
+ }
+
private TagHelperResolutionResult GetTagHelperResolutionResult(JObject jsonObject)
{
var serializer = new JsonSerializer();
diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperDescriptorConventionsTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperDescriptorConventionsTest.cs
index fa6de930b7..f0bd076179 100644
--- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperDescriptorConventionsTest.cs
+++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperDescriptorConventionsTest.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Language;
-using Microsoft.CodeAnalysis.Razor;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
diff --git a/test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTagHelperDescriptorFactoryTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperDescriptorFactoryTest.cs
similarity index 93%
rename from test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTagHelperDescriptorFactoryTest.cs
rename to test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperDescriptorFactoryTest.cs
index df25cd201d..fcfd3b7bf9 100644
--- a/test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTagHelperDescriptorFactoryTest.cs
+++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperDescriptorFactoryTest.cs
@@ -3,19 +3,22 @@
using System.Collections.Generic;
using System.Reflection;
-using Microsoft.AspNetCore.Razor.Language;
-using Xunit;
using System.Threading.Tasks;
+using Microsoft.AspNetCore.Razor.Language;
+using Microsoft.CodeAnalysis;
+using Xunit;
-namespace Microsoft.CodeAnalysis.Razor.Workspaces
+namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
public class ViewComponentTagHelperDescriptorFactoryTest
{
+ private static readonly Assembly _assembly = typeof(ViewComponentTagHelperDescriptorFactoryTest).GetTypeInfo().Assembly;
+
[Fact]
public void CreateDescriptor_UnderstandsStringParameters()
{
// Arrange
- var testCompilation = TestCompilation.Create();
+ var testCompilation = TestCompilation.Create(_assembly);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(StringParameterViewComponent).FullName);
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
@@ -53,7 +56,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public void CreateDescriptor_UnderstandsVariousParameterTypes()
{
// Arrange
- var testCompilation = TestCompilation.Create();
+ var testCompilation = TestCompilation.Create(_assembly);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(VariousParameterViewComponent).FullName);
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
@@ -99,7 +102,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public void CreateDescriptor_UnderstandsGenericParameters()
{
// Arrange
- var testCompilation = TestCompilation.Create();
+ var testCompilation = TestCompilation.Create(_assembly);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(GenericParameterViewComponent).FullName);
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
@@ -137,7 +140,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public void CreateDescriptor_AddsDiagnostic_ForViewComponentWithNoInvokeMethod()
{
// Arrange
- var testCompilation = TestCompilation.Create();
+ var testCompilation = TestCompilation.Create(_assembly);
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(ViewComponentWithoutInvokeMethod).FullName);
@@ -154,7 +157,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public void CreateDescriptor_ForViewComponentWithInvokeAsync_UnderstandsGenericTask()
{
// Arrange
- var testCompilation = TestCompilation.Create();
+ var testCompilation = TestCompilation.Create(_assembly);
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithGenericTask).FullName);
@@ -170,7 +173,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public void CreateDescriptor_ForViewComponentWithInvokeAsync_UnderstandsNonGenericTask()
{
// Arrange
- var testCompilation = TestCompilation.Create();
+ var testCompilation = TestCompilation.Create(_assembly);
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithNonGenericTask).FullName);
@@ -186,7 +189,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public void CreateDescriptor_ForViewComponentWithInvokeAsync_DoesNotUnderstandVoid()
{
// Arrange
- var testCompilation = TestCompilation.Create();
+ var testCompilation = TestCompilation.Create(_assembly);
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithString).FullName);
@@ -203,7 +206,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public void CreateDescriptor_ForViewComponentWithInvokeAsync_DoesNotUnderstandString()
{
// Arrange
- var testCompilation = TestCompilation.Create();
+ var testCompilation = TestCompilation.Create(_assembly);
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithString).FullName);
@@ -220,7 +223,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public void CreateDescriptor_ForViewComponentWithInvoke_DoesNotUnderstandVoid()
{
// Arrange
- var testCompilation = TestCompilation.Create();
+ var testCompilation = TestCompilation.Create(_assembly);
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(SyncViewComponentWithVoid).FullName);
@@ -237,7 +240,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public void CreateDescriptor_ForViewComponentWithInvoke_DoesNotUnderstandNonGenericTask()
{
// Arrange
- var testCompilation = TestCompilation.Create();
+ var testCompilation = TestCompilation.Create(_assembly);
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(SyncViewComponentWithNonGenericTask).FullName);
@@ -254,7 +257,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public void CreateDescriptor_ForViewComponentWithInvoke_DoesNotUnderstandGenericTask()
{
// Arrange
- var testCompilation = TestCompilation.Create();
+ var testCompilation = TestCompilation.Create(_assembly);
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(SyncViewComponentWithGenericTask).FullName);
diff --git a/test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTagHelperDescriptorProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperDescriptorProviderTest.cs
similarity index 87%
rename from test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTagHelperDescriptorProviderTest.cs
rename to test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperDescriptorProviderTest.cs
index 6a466c8c5e..fe5ec8b068 100644
--- a/test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTagHelperDescriptorProviderTest.cs
+++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperDescriptorProviderTest.cs
@@ -2,15 +2,20 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
+using System.Reflection;
using Microsoft.AspNetCore.Razor.Language;
+using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.Razor;
using Xunit;
-namespace Microsoft.CodeAnalysis.Razor
+namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
// This is just a basic integration test. There are detailed tests for the VCTH visitor and descriptor factory.
public class ViewComponentTagHelperDescriptorProviderTest
{
+ private static readonly Assembly _assembly = typeof(ViewComponentTagHelperDescriptorProviderTest).GetTypeInfo().Assembly;
+
[Fact]
public void DescriptorProvider_FindsVCTH()
{
@@ -22,7 +27,7 @@ namespace Microsoft.CodeAnalysis.Razor
}
";
- var testCompilation = TestCompilation.Create(CSharpSyntaxTree.ParseText(code));
+ var testCompilation = TestCompilation.Create(_assembly, CSharpSyntaxTree.ParseText(code));
var context = TagHelperDescriptorProviderContext.Create();
context.SetCompilation(testCompilation);
diff --git a/test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTypeVisitorTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTypeVisitorTest.cs
similarity index 96%
rename from test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTypeVisitorTest.cs
rename to test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTypeVisitorTest.cs
index a28d0d7c63..48e8cfeec8 100644
--- a/test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTypeVisitorTest.cs
+++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTypeVisitorTest.cs
@@ -3,13 +3,17 @@
using System;
using System.Collections.Generic;
+using System.Reflection;
+using Microsoft.CodeAnalysis;
using Xunit;
-namespace Microsoft.CodeAnalysis.Razor
+namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
public class ViewComponentTypeVisitorTest
{
- private static Compilation Compilation { get; } = TestCompilation.Create();
+ private static readonly Assembly _assembly = typeof(ViewComponentTypeVisitorTest).GetTypeInfo().Assembly;
+
+ private static Compilation Compilation { get; } = TestCompilation.Create(_assembly);
// In practice MVC will provide a marker attribute for ViewComponents. To prevent a circular reference between MVC and Razor
// we can use a test class as a marker.
diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Microsoft.AspNetCore.Razor.Test.Common.csproj b/test/Microsoft.AspNetCore.Razor.Test.Common/Microsoft.AspNetCore.Razor.Test.Common.csproj
index 084795ffbd..7aa0660765 100644
--- a/test/Microsoft.AspNetCore.Razor.Test.Common/Microsoft.AspNetCore.Razor.Test.Common.csproj
+++ b/test/Microsoft.AspNetCore.Razor.Test.Common/Microsoft.AspNetCore.Razor.Test.Common.csproj
@@ -13,6 +13,8 @@
+
+
diff --git a/test/Microsoft.CodeAnalysis.Razor.Test/TestCompilation.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/TestCompilation.cs
similarity index 59%
rename from test/Microsoft.CodeAnalysis.Razor.Test/TestCompilation.cs
rename to test/Microsoft.AspNetCore.Razor.Test.Common/TestCompilation.cs
index ab5869c6cb..8628904ddb 100644
--- a/test/Microsoft.CodeAnalysis.Razor.Test/TestCompilation.cs
+++ b/test/Microsoft.AspNetCore.Razor.Test.Common/TestCompilation.cs
@@ -1,43 +1,37 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.Extensions.DependencyModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.Extensions.DependencyModel;
using Xunit;
-namespace Microsoft.CodeAnalysis.Razor
+namespace Microsoft.CodeAnalysis
{
public static class TestCompilation
{
- private static IEnumerable _metadataReferences;
+ private static Dictionary> _assemblyMetadataReferences =
+ new Dictionary>();
- public static IEnumerable MetadataReferences
+ public static IEnumerable GetMetadataReferences(Assembly assembly)
{
- get
- {
- if (_metadataReferences == null)
- {
- var currentAssembly = typeof(TestCompilation).GetTypeInfo().Assembly;
- var dependencyContext = DependencyContext.Load(currentAssembly);
+ var dependencyContext = DependencyContext.Load(assembly);
- _metadataReferences = dependencyContext.CompileLibraries
- .SelectMany(l => l.ResolveReferencePaths())
- .Select(assemblyPath => MetadataReference.CreateFromFile(assemblyPath))
- .ToArray();
- }
+ var metadataReferences = dependencyContext.CompileLibraries
+ .SelectMany(l => l.ResolveReferencePaths())
+ .Select(assemblyPath => MetadataReference.CreateFromFile(assemblyPath))
+ .ToArray();
- return _metadataReferences;
- }
+ return metadataReferences;
}
public static string AssemblyName => "TestAssembly";
- public static Compilation Create(SyntaxTree syntaxTree = null)
+ public static Compilation Create(Assembly assembly, SyntaxTree syntaxTree = null)
{
IEnumerable syntaxTrees = null;
@@ -46,7 +40,13 @@ namespace Microsoft.CodeAnalysis.Razor
syntaxTrees = new[] { syntaxTree };
}
- var compilation = CSharpCompilation.Create(AssemblyName, syntaxTrees, MetadataReferences);
+ if (!_assemblyMetadataReferences.TryGetValue(assembly, out IEnumerable metadataReferences))
+ {
+ metadataReferences = GetMetadataReferences(assembly);
+ _assemblyMetadataReferences[assembly] = metadataReferences;
+ }
+
+ var compilation = CSharpCompilation.Create(AssemblyName, syntaxTrees, metadataReferences);
EnsureValidCompilation(compilation);
diff --git a/test/Microsoft.CodeAnalysis.Razor.Test/DefaultTagHelperDescriptorFactoryTest.cs b/test/Microsoft.CodeAnalysis.Razor.Test/DefaultTagHelperDescriptorFactoryTest.cs
index 5987b16aa9..3d1ea6ff3a 100644
--- a/test/Microsoft.CodeAnalysis.Razor.Test/DefaultTagHelperDescriptorFactoryTest.cs
+++ b/test/Microsoft.CodeAnalysis.Razor.Test/DefaultTagHelperDescriptorFactoryTest.cs
@@ -1,27 +1,28 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Legacy;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Razor.Workspaces.Test;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
using Xunit;
namespace Microsoft.CodeAnalysis.Razor.Workspaces
{
public class DefaultTagHelperDescriptorFactoryTest
{
- protected static readonly AssemblyName TagHelperDescriptorFactoryTestAssembly =
- typeof(DefaultTagHelperDescriptorFactoryTest).GetTypeInfo().Assembly.GetName();
+ private static readonly Assembly _assembly = typeof(DefaultTagHelperDescriptorFactoryTest).GetTypeInfo().Assembly;
+
+ protected static readonly AssemblyName TagHelperDescriptorFactoryTestAssembly = _assembly.GetName();
protected static readonly string AssemblyName = TagHelperDescriptorFactoryTestAssembly.Name;
- private static Compilation Compilation { get; } = TestCompilation.Create();
+ private static Compilation Compilation { get; } = TestCompilation.Create(_assembly);
public static TheoryData RequiredAttributeParserErrorData
{
@@ -1329,7 +1330,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
{{
}}";
var syntaxTree = CSharpSyntaxTree.ParseText(text);
- var compilation = TestCompilation.Create(syntaxTree);
+ var compilation = TestCompilation.Create(_assembly, syntaxTree);
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
var attribute = tagHelperType.GetAttributes().Single();
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
@@ -1510,7 +1511,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public string SomeAttribute {{ get; set; }}
}}";
var syntaxTree = CSharpSyntaxTree.ParseText(text);
- var compilation = TestCompilation.Create(syntaxTree);
+ var compilation = TestCompilation.Create(_assembly, syntaxTree);
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
@@ -1550,7 +1551,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public System.Collections.Generic.IDictionary SomeAttribute {{ get; set; }}
}}";
var syntaxTree = CSharpSyntaxTree.ParseText(text);
- var compilation = TestCompilation.Create(syntaxTree);
+ var compilation = TestCompilation.Create(_assembly, syntaxTree);
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
@@ -1593,7 +1594,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public string InvalidProperty {{ get; set; }}
}}";
var syntaxTree = CSharpSyntaxTree.ParseText(text);
- var compilation = TestCompilation.Create(syntaxTree);
+ var compilation = TestCompilation.Create(_assembly, syntaxTree);
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
@@ -1636,7 +1637,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public System.Collections.Generic.IDictionary InvalidProperty {{ get; set; }}
}}";
var syntaxTree = CSharpSyntaxTree.ParseText(text);
- var compilation = TestCompilation.Create(syntaxTree);
+ var compilation = TestCompilation.Create(_assembly, syntaxTree);
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
@@ -1678,7 +1679,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
{{
}}";
var syntaxTree = CSharpSyntaxTree.ParseText(text);
- var compilation = TestCompilation.Create(syntaxTree);
+ var compilation = TestCompilation.Create(_assembly, syntaxTree);
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
@@ -1719,7 +1720,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
{{
}}";
var syntaxTree = CSharpSyntaxTree.ParseText(text);
- var compilation = TestCompilation.Create(syntaxTree);
+ var compilation = TestCompilation.Create(_assembly, syntaxTree);
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
@@ -2031,7 +2032,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
{
// Arrange
var errorSink = new ErrorSink();
- var sytnaxTree = CSharpSyntaxTree.ParseText(@"
+ var syntaxTree = CSharpSyntaxTree.ParseText(@"
using Microsoft.AspNetCore.Razor.TagHelpers;
///
@@ -2043,7 +2044,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
public class DocumentedTagHelper : " + typeof(AspNetCore.Razor.TagHelpers.TagHelper).Name + @"
{
}");
- var compilation = TestCompilation.Create(sytnaxTree);
+ var compilation = TestCompilation.Create(_assembly, syntaxTree);
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: true);
var typeSymbol = compilation.GetTypeByMetadataName("DocumentedTagHelper");
var expectedDocumentation =
@@ -2069,7 +2070,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
{
// Arrange
var errorSink = new ErrorSink();
- var sytnaxTree = CSharpSyntaxTree.ParseText(@"
+ var syntaxTree = CSharpSyntaxTree.ParseText(@"
using System.Collections.Generic;
public class DocumentedTagHelper : " + typeof(AspNetCore.Razor.TagHelpers.TagHelper).FullName + @"
@@ -2092,7 +2093,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
///
public List RemarksAndSummaryProperty { get; set; }
}");
- var compilation = TestCompilation.Create(sytnaxTree);
+ var compilation = TestCompilation.Create(_assembly, syntaxTree);
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: true);
var typeSymbol = compilation.GetTypeByMetadataName("DocumentedTagHelper");
var expectedDocumentations = new[]
diff --git a/test/Microsoft.CodeAnalysis.Razor.Test/Microsoft.CodeAnalysis.Razor.Test.csproj b/test/Microsoft.CodeAnalysis.Razor.Test/Microsoft.CodeAnalysis.Razor.Test.csproj
index 90a05dde3d..a05a593524 100644
--- a/test/Microsoft.CodeAnalysis.Razor.Test/Microsoft.CodeAnalysis.Razor.Test.csproj
+++ b/test/Microsoft.CodeAnalysis.Razor.Test/Microsoft.CodeAnalysis.Razor.Test.csproj
@@ -23,6 +23,7 @@
+
diff --git a/test/Microsoft.CodeAnalysis.Razor.Test/TagHelperTypeVisitorTest.cs b/test/Microsoft.CodeAnalysis.Razor.Test/TagHelperTypeVisitorTest.cs
index 5af8816ff7..8f14017c91 100644
--- a/test/Microsoft.CodeAnalysis.Razor.Test/TagHelperTypeVisitorTest.cs
+++ b/test/Microsoft.CodeAnalysis.Razor.Test/TagHelperTypeVisitorTest.cs
@@ -4,12 +4,15 @@
using Microsoft.AspNetCore.Razor.TagHelpers;
using System.Collections.Generic;
using Xunit;
+using System.Reflection;
namespace Microsoft.CodeAnalysis.Razor.Workspaces
{
public class TagHelperTypeVisitorTest
{
- private static Compilation Compilation { get; } = TestCompilation.Create();
+ private static readonly Assembly _assembly = typeof(TagHelperTypeVisitorTest).GetTypeInfo().Assembly;
+
+ private static Compilation Compilation { get; } = TestCompilation.Create(_assembly);
private static INamedTypeSymbol ITagHelperSymbol { get; } = Compilation.GetTypeByMetadataName(TagHelperTypes.ITagHelper);