public override bool TryResolveConfiguration(ProjectConfigurationProviderContext context, out ProjectConfiguration configuration) { if (!HasRazorCoreCapability(context)) { configuration = null; return(false); } if (!HasRazorCoreConfigurationCapability(context)) { // Razor project is < 2.1, we don't handle that. configuration = null; return(false); } var projectInstance = context.ProjectInstance; if (!TryGetConfiguration(projectInstance, out configuration)) { configuration = null; return(false); } return(true); }
public override bool TryResolveConfiguration(ProjectConfigurationProviderContext context, out ProjectConfiguration configuration) { if (HasRazorCoreCapability(context)) { configuration = null; return(false); } var compilationReferences = context.ProjectInstance.GetItems(ReferencePathWithRefAssembliesItemType); foreach (var compilationReference in compilationReferences) { var assemblyFullPath = compilationReference.EvaluatedInclude; if (assemblyFullPath.EndsWith(SystemWebRazorAssemblyFileName, FilePathComparison.Instance)) { var potentialPathSeparator = assemblyFullPath[assemblyFullPath.Length - SystemWebRazorAssemblyFileName.Length - 1]; if (potentialPathSeparator == '/' || potentialPathSeparator == '\\') { configuration = new ProjectConfiguration(UnsupportedRazorConfiguration.Instance, Array.Empty <OmniSharpHostDocument>(), rootNamespace: null); return(true); } } } configuration = null; return(false); }
private ProjectConfigurationProviderContext BuildContext(params string[] referencePaths) { var projectInstance = new ProjectInstance(ProjectRootElement.Create()); foreach (var path in referencePaths) { projectInstance.AddItem(SystemWebConfigurationProvider.ReferencePathWithRefAssembliesItemType, path); } var context = new ProjectConfigurationProviderContext(Array.Empty <string>(), projectInstance); return(context); }
private ProjectConfigurationProviderContext BuildContext(params string[] referencePaths) { var projectCapabilities = new[] { CoreProjectConfigurationProvider.DotNetCoreRazorCapability }; var projectInstance = new ProjectInstance(ProjectRootElement.Create()); foreach (var path in referencePaths) { projectInstance.AddItem(FallbackConfigurationProvider.ReferencePathWithRefAssembliesItemType, path); } var context = new ProjectConfigurationProviderContext(projectCapabilities, projectInstance); return(context); }
public void HasRazorCoreConfigurationCapability_DotNetCoreRazorConfigCapability_ReturnsTrue() { // Arrange var projectCapabilities = new[] { CoreProjectConfigurationProvider.DotNetCoreRazorConfigurationCapability }; var projectInstance = new ProjectInstance(ProjectRootElement.Create()); var context = new ProjectConfigurationProviderContext(projectCapabilities, projectInstance); var provider = new TestCoreProjectConfigurationProvider(); // Act var result = provider.HasRazorCoreConfigurationCapability(context); // Assert Assert.True(result); }
public void HasRazorCoreCapability_NoCapabilities_ReturnsFalse() { // Arrange var projectCapabilities = Array.Empty <string>(); var projectInstance = new ProjectInstance(ProjectRootElement.Create()); var context = new ProjectConfigurationProviderContext(projectCapabilities, projectInstance); var provider = new TestCoreProjectConfigurationProvider(); // Act var result = provider.HasRazorCoreCapability(context); // Assert Assert.False(result); }
public void TryResolveConfiguration_NoCoreCapability_ReturnsFalse() { // Arrange var projectCapabilities = Array.Empty <string>(); var projectInstance = new ProjectInstance(ProjectRootElement.Create()); var context = new ProjectConfigurationProviderContext(projectCapabilities, projectInstance); var provider = new LatestProjectConfigurationProvider(); // Act var result = provider.TryResolveConfiguration(context, out var configuration); // Assert Assert.False(result); Assert.Null(configuration); }
public override bool TryResolveConfiguration(ProjectConfigurationProviderContext context, out ProjectConfiguration configuration) { if (!HasRazorCoreCapability(context)) { configuration = null; return(false); } var compilationReferences = context.ProjectInstance.GetItems(ReferencePathWithRefAssembliesItemType); string mvcReferenceFullPath = null; foreach (var compilationReference in compilationReferences) { var assemblyFullPath = compilationReference.EvaluatedInclude; if (assemblyFullPath.EndsWith(MvcAssemblyFileName, FilePathComparison.Instance)) { var potentialPathSeparator = assemblyFullPath[assemblyFullPath.Length - MvcAssemblyFileName.Length - 1]; if (potentialPathSeparator == '/' || potentialPathSeparator == '\\') { mvcReferenceFullPath = assemblyFullPath; break; } } } if (mvcReferenceFullPath == null) { configuration = null; return(false); } var version = GetAssemblyVersion(mvcReferenceFullPath); if (version == null) { configuration = null; return(false); } var razorConfiguration = FallbackRazorConfiguration.SelectConfiguration(version); configuration = new ProjectConfiguration(razorConfiguration, Array.Empty <OmniSharpHostDocument>(), rootNamespace: null); return(true); }
public void TryResolveConfiguration_RazorConfigurationCapability_ReturnsFalse() { // Arrange var projectCapabilities = new[] { CoreProjectConfigurationProvider.DotNetCoreRazorCapability, CoreProjectConfigurationProvider.DotNetCoreRazorConfigurationCapability }; var projectInstance = new ProjectInstance(ProjectRootElement.Create()); var context = new ProjectConfigurationProviderContext(projectCapabilities, projectInstance); var provider = new TestLegacyConfigurationProvider(MvcAssemblyVersion); // Act var result = provider.TryResolveConfiguration(context, out var configuration); // Assert Assert.False(result); Assert.Null(configuration); }
public void TryResolveConfiguration_RazorCoreCapability_ReturnsFalse() { // Arrange var projectCapabilities = new[] { CoreProjectConfigurationProvider.DotNetCoreRazorCapability, }; var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem(SystemWebConfigurationProvider.ReferencePathWithRefAssembliesItemType, SystemWebConfigurationProvider.SystemWebRazorAssemblyFileName); var context = new ProjectConfigurationProviderContext(projectCapabilities, projectInstance); var provider = new SystemWebConfigurationProvider(); // Act var result = provider.TryResolveConfiguration(context, out var configuration); // Assert Assert.False(result); Assert.Null(configuration); }
protected bool HasRazorCoreConfigurationCapability(ProjectConfigurationProviderContext context) => context.ProjectCapabilities.Contains(DotNetCoreRazorConfigurationCapability);
public override bool TryResolveConfiguration(ProjectConfigurationProviderContext context, out ProjectConfiguration configuration) { throw new NotImplementedException(); }
public new bool HasRazorCoreConfigurationCapability(ProjectConfigurationProviderContext context) => base.HasRazorCoreConfigurationCapability(context);