Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
        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);
        }
Example #11
0
 protected bool HasRazorCoreConfigurationCapability(ProjectConfigurationProviderContext context) =>
 context.ProjectCapabilities.Contains(DotNetCoreRazorConfigurationCapability);
Example #12
0
 public override bool TryResolveConfiguration(ProjectConfigurationProviderContext context, out ProjectConfiguration configuration)
 {
     throw new NotImplementedException();
 }
Example #13
0
 public new bool HasRazorCoreConfigurationCapability(ProjectConfigurationProviderContext context) => base.HasRazorCoreConfigurationCapability(context);