public void SetProperty_MaxSupportedLangVersion(LanguageVersion?maxSupportedLangVersion)
        {
            using var environment = new TestEnvironment(typeof(CSharpParseOptionsChangingService));

            var hierarchy = environment.CreateHierarchy("CSharpProject", "Bin", projectRefPath: null, projectCapabilities: "CSharp");
            var storage   = Assert.IsAssignableFrom <IVsBuildPropertyStorage>(hierarchy);

            Assert.True(ErrorHandler.Succeeded(
                            storage.SetPropertyValue(
                                "MaxSupportedLangVersion", null, (uint)_PersistStorageType.PST_PROJECT_FILE, maxSupportedLangVersion?.ToDisplayString())));

            _ = CSharpHelpers.CreateCSharpProject(environment, "Test", hierarchy);

            var project = environment.Workspace.CurrentSolution.Projects.Single();

            var oldParseOptions = (CSharpParseOptions)project.ParseOptions;

            const LanguageVersion attemptedVersion = LanguageVersion.CSharp8;

            var canApply = environment.Workspace.CanApplyParseOptionChange(
                oldParseOptions,
                oldParseOptions.WithLanguageVersion(attemptedVersion),
                project);

            if (maxSupportedLangVersion.HasValue)
            {
                Assert.Equal(attemptedVersion <= maxSupportedLangVersion.Value, canApply);
            }
            else
            {
                Assert.True(canApply);
            }
        }
Пример #2
0
        public static CSharpProjectShim CreateCSharpProject(TestEnvironment environment, string projectName)
        {
            var projectBinPath = Path.GetTempPath();
            var hierarchy      = environment.CreateHierarchy(projectName, projectBinPath, projectRefPath: null, projectCapabilities: "CSharp");

            return(CreateCSharpProject(environment, projectName, hierarchy));
        }
Пример #3
0
        public void SetProperty_MaxSupportedLangVersion_NotSet()
        {
            var catalog = TestEnvironment.s_exportCatalog.Value
                          .WithParts(
                typeof(CSharpParseOptionsChangingService));

            var factory = ExportProviderCache.GetOrCreateExportProviderFactory(catalog);

            using var environment = new TestEnvironment(exportProviderFactory: factory);

            var hierarchy = environment.CreateHierarchy("CSharpProject", "Bin", projectRefPath: null, projectCapabilities: "CSharp");
            var storage   = Assert.IsAssignableFrom <IVsBuildPropertyStorage>(hierarchy);

            _ = CSharpHelpers.CreateCSharpProject(environment, "Test", hierarchy);

            var project = environment.Workspace.CurrentSolution.Projects.Single();

            var oldParseOptions = (CSharpParseOptions)project.ParseOptions;

            const LanguageVersion attemptedVersion = LanguageVersion.CSharp8;

            var canApply = environment.Workspace.CanApplyParseOptionChange(
                oldParseOptions,
                oldParseOptions.WithLanguageVersion(attemptedVersion),
                project);

            Assert.True(canApply);
        }
Пример #4
0
        public static async Task <CPSProject> CreateNonCompilableProjectAsync(
            TestEnvironment environment,
            string projectName,
            string projectFilePath
            )
        {
            var hierarchy = environment.CreateHierarchy(
                projectName,
                projectBinPath: null,
                projectRefPath: null,
                ""
                );
            var cpsProjectFactory =
                environment.ExportProvider.GetExportedValue <IWorkspaceProjectContextFactory>();

            return((CPSProject)await cpsProjectFactory.CreateProjectContextAsync(
                       NoCompilationConstants.LanguageName,
                       projectName,
                       projectFilePath,
                       Guid.NewGuid(),
                       hierarchy,
                       binOutputPath : null,
                       CancellationToken.None
                       ));
        }
Пример #5
0
        public static async Task <CPSProject> CreateCSharpCPSProjectAsync(
            TestEnvironment environment,
            string projectName,
            string projectFilePath,
            string binOutputPath,
            Guid projectGuid,
            params string[] commandLineArguments
            )
        {
            var hierarchy = environment.CreateHierarchy(
                projectName,
                binOutputPath,
                projectRefPath: null,
                "CSharp"
                );
            var cpsProjectFactory =
                environment.ExportProvider.GetExportedValue <IWorkspaceProjectContextFactory>();
            var cpsProject = (CPSProject)await cpsProjectFactory.CreateProjectContextAsync(
                LanguageNames.CSharp,
                projectName,
                projectFilePath,
                projectGuid,
                hierarchy,
                binOutputPath,
                CancellationToken.None
                );

            cpsProject.SetOptions(ImmutableArray.Create(commandLineArguments));

            return(cpsProject);
        }
Пример #6
0
        public static CPSProject CreateNonCompilableProject(TestEnvironment environment, string projectName, string projectFilePath)
        {
            var hierarchy         = environment.CreateHierarchy(projectName, projectFilePath, "");
            var cpsProjectFactory = environment.ExportProvider.GetExportedValue <IWorkspaceProjectContextFactory>();

            return((CPSProject)cpsProjectFactory.CreateProjectContext(
                       NoCompilationConstants.LanguageName,
                       projectName,
                       projectFilePath,
                       Guid.NewGuid(),
                       hierarchy,
                       binOutputPath: null));
        }
Пример #7
0
        public static CSharpProjectShimWithServices CreateCSharpProject(TestEnvironment environment, string projectName)
        {
            var hierarchy = environment.CreateHierarchy(projectName, "CSharp");

            return new CSharpProjectShimWithServices(
                new MockCSharpProjectRoot(hierarchy),
                environment.ProjectTracker,
                reportExternalErrorCreatorOpt: null,
                projectSystemName: projectName,
                hierarchy: hierarchy,
                serviceProvider: environment.ServiceProvider,
                visualStudioWorkspaceOpt: null,
                hostDiagnosticUpdateSourceOpt: null);
        }
Пример #8
0
        public static CSharpProjectShimWithServices CreateCSharpProject(TestEnvironment environment, string projectName)
        {
            var hierarchy = environment.CreateHierarchy(projectName, "CSharp");

            return(new CSharpProjectShimWithServices(
                       new MockCSharpProjectRoot(hierarchy),
                       environment.ProjectTracker,
                       reportExternalErrorCreatorOpt: null,
                       projectSystemName: projectName,
                       hierarchy: hierarchy,
                       serviceProvider: environment.ServiceProvider,
                       visualStudioWorkspaceOpt: null,
                       hostDiagnosticUpdateSourceOpt: null));
        }
Пример #9
0
        public static CSharpProjectShim CreateCSharpProject(TestEnvironment environment, string projectName)
        {
            var projectBinPath = Path.GetTempPath();
            var hierarchy      = environment.CreateHierarchy(projectName, projectBinPath, "CSharp");

            return(new CSharpProjectShim(
                       new MockCSharpProjectRoot(hierarchy),
                       projectSystemName: projectName,
                       hierarchy: hierarchy,
                       serviceProvider: environment.ServiceProvider,
                       threadingContext: environment.ThreadingContext,
                       hostDiagnosticUpdateSourceOpt: null,
                       commandLineParserServiceOpt: new CSharpCommandLineParserService()));
        }
Пример #10
0
        public static CPSProject CreateNonCompilableProject(TestEnvironment environment, string projectName, string projectFilePath)
        {
            var hierarchy = environment.CreateHierarchy(projectName, projectFilePath, "");

            return(CPSProjectFactory.CreateCPSProject(
                       environment.ProjectTracker,
                       environment.ServiceProvider,
                       hierarchy,
                       projectName,
                       projectFilePath,
                       Guid.NewGuid(),
                       NoCompilationConstants.LanguageName,
                       commandLineParserService: null,
                       binOutputPath: null));
        }
Пример #11
0
        public void RefPathPassedToWorkspace(string expectedRefPath)
        {
            using var environment = new TestEnvironment();

            var hierarchyWithRefPath =
                environment.CreateHierarchy(
                    "WithRefPath",
                    @"Z:\WithRefPath.dll",
                    expectedRefPath,
                    "CSharp");

            var project          = CSharpHelpers.CreateCSharpProject(environment, "WithRefPath", hierarchyWithRefPath);
            var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single();

            Assert.Equal(expectedRefPath, workspaceProject.OutputRefFilePath);
        }
Пример #12
0
        public static CSharpProjectShim CreateCSharpProject(TestEnvironment environment, string projectName)
        {
            var projectBinPath = Path.GetTempPath();
            var hierarchy      = environment.CreateHierarchy(projectName, projectBinPath, "CSharp");

            return(new CSharpProjectShim(
                       new MockCSharpProjectRoot(hierarchy),
                       environment.ProjectTracker,
                       reportExternalErrorCreatorOpt: null,
                       projectSystemName: projectName,
                       hierarchy: hierarchy,
                       serviceProvider: environment.ServiceProvider,
                       visualStudioWorkspaceOpt: null,
                       hostDiagnosticUpdateSourceOpt: null,
                       commandLineParserServiceOpt: new CSharpCommandLineParserService()));
        }
Пример #13
0
        public static CPSProject CreateCSharpCPSProject(TestEnvironment environment, string projectName, Guid projectGuid, params string[] commandLineArguments)
        {
            var projectFilePath       = Path.GetTempPath();
            var hierarchy             = environment.CreateHierarchy(projectName, projectFilePath, "CSharp");
            var commandLineForOptions = string.Join(" ", commandLineArguments);

            return(CPSProjectFactory.CreateCPSProject(
                       environment.ProjectTracker,
                       environment.ServiceProvider,
                       hierarchy,
                       projectName,
                       projectFilePath,
                       projectGuid,
                       LanguageNames.CSharp,
                       new TestCSharpCommandLineParserService(),
                       commandLineForOptions));
        }
Пример #14
0
        public static CPSProject CreateCSharpCPSProject(TestEnvironment environment, string projectName, Guid projectGuid, params string[] commandLineArguments)
        {
            var projectFilePath = Path.GetTempPath();
            var hierarchy = environment.CreateHierarchy(projectName, projectFilePath, "CSharp");
            var commandLineForOptions = string.Join(" ", commandLineArguments);

            return CPSProjectFactory.CreateCPSProject(
                environment.ProjectTracker,
                environment.ServiceProvider,
                hierarchy,
                projectName,
                projectFilePath,
                projectGuid,
                LanguageNames.CSharp,
                new TestCSharpCommandLineParserService(),
                commandLineForOptions);
        }
Пример #15
0
        public static CPSProject CreateCSharpCPSProject(TestEnvironment environment, string projectName, string projectFilePath, string binOutputPath, Guid projectGuid, params string[] commandLineArguments)
        {
            var hierarchy         = environment.CreateHierarchy(projectName, binOutputPath, projectRefPath: null, "CSharp");
            var cpsProjectFactory = environment.ExportProvider.GetExportedValue <IWorkspaceProjectContextFactory>();
            var cpsProject        = (CPSProject)cpsProjectFactory.CreateProjectContext(
                LanguageNames.CSharp,
                projectName,
                projectFilePath,
                projectGuid,
                hierarchy,
                binOutputPath);

            var commandLineForOptions = string.Join(" ", commandLineArguments);

            cpsProject.SetOptions(commandLineForOptions);

            return(cpsProject);
        }
Пример #16
0
        public static CPSProject CreateCSharpCPSProject(TestEnvironment environment, string projectName, Guid projectGuid, string projectTypeGuid, params string[] commandLineArguments)
        {
            var tempPath = Path.GetTempPath();
            var projectFilePath = Path.Combine(tempPath, projectName);
            var hierarchy = environment.CreateHierarchy(projectName, projectFilePath, "CSharp");
            var parsedArguments = GetParsedCommandLineArguments(hierarchy, commandLineArguments);

            return CPSProjectFactory.CreateCPSProject(
                environment.ProjectTracker,
                environment.ServiceProvider,
                hierarchy,
                projectName,
                projectFilePath,
                LanguageNames.CSharp,
                projectGuid,
                projectTypeGuid,
                parsedArguments);
        }