private ProjectBuilder AddProject(AnalyzerLanguage language, string projectName, bool createExtraEmptyFile)
        {
            var languageName = language == AnalyzerLanguage.CSharp
                ? LanguageNames.CSharp
                : LanguageNames.VisualBasic;

            var project = Solution.AddProject(projectName, projectName, languageName);

            var projectBuilder = ProjectBuilder.FromProject(project)
                                 .AddReferences(
                FrameworkMetadataReference.Mscorlib,
                FrameworkMetadataReference.System,
                FrameworkMetadataReference.SystemCore);

            if (createExtraEmptyFile)
            {
                // adding an extra file to the project
                // this won't trigger any issues, but it keeps a reference to the original ParseOption, so
                // if an analyzer/codefix changes the language version, Roslyn throws an ArgumentException
                projectBuilder = projectBuilder
                                 .AddSnippet(string.Empty, fileName: "ExtraEmptyFile.g." + language.FileExtension);
            }

            return(projectBuilder);
        }
Esempio n. 2
0
        private ProjectBuilder AddProject(AnalyzerLanguage language, string projectName, bool createExtraEmptyFile)
        {
            var languageName = language == AnalyzerLanguage.CSharp
                ? LanguageNames.CSharp
                : LanguageNames.VisualBasic;

            var project = Solution.AddProject(projectName, projectName, languageName);


            var projectBuilder = ProjectBuilder
                                 .FromProject(project)
                                 .AddReferences(MetadataReferenceFacade.GetProjectDefaultReferences());

            if (language == AnalyzerLanguage.VisualBasic)
            {
                // Need a reference to the VB dll to be able to use the Module keyword
                projectBuilder = projectBuilder.AddReferences(MetadataReferenceFacade.GetMicrosoftVisualBasic());
            }

            if (createExtraEmptyFile)
            {
                // adding an extra file to the project
                // this won't trigger any issues, but it keeps a reference to the original ParseOption, so
                // if an analyzer/codefix changes the language version, Roslyn throws an ArgumentException
                projectBuilder = projectBuilder
                                 .AddSnippet(string.Empty, fileName: "ExtraEmptyFile.g." + language.FileExtension);
            }

            return(projectBuilder);
        }
Esempio n. 3
0
        private ProjectBuilder AddProject(AnalyzerLanguage language, string projectName, bool createExtraEmptyFile, OutputKind outputKind = OutputKind.DynamicallyLinkedLibrary)
        {
            var languageName = language == AnalyzerLanguage.CSharp
                ? LanguageNames.CSharp
                : LanguageNames.VisualBasic;

            var project = Solution.AddProject(projectName, projectName, languageName);

            var compilationOptions = project.CompilationOptions.WithOutputKind(outputKind);

            if (languageName == LanguageNames.CSharp)
            {
                compilationOptions = ((CSharpCompilationOptions)compilationOptions).WithAllowUnsafe(true);
            }
            project = project.WithCompilationOptions(compilationOptions);

            var projectBuilder = ProjectBuilder
                                 .FromProject(project)
                                 .AddReferences(MetadataReferenceFacade.GetProjectDefaultReferences());

            if (language == AnalyzerLanguage.VisualBasic)
            {
                // Need a reference to the VB dll to be able to use the Module keyword
                projectBuilder = projectBuilder.AddReferences(MetadataReferenceFacade.GetMicrosoftVisualBasic());
            }

            if (createExtraEmptyFile)
            {
                // adding an extra file to the project
                // this won't trigger any issues, but it keeps a reference to the original ParseOption, so
                // if an analyzer/codefix changes the language version, Roslyn throws an ArgumentException
                projectBuilder = projectBuilder
                                 .AddSnippet(string.Empty, fileName: "ExtraEmptyFile.g." + language.FileExtension);
            }

            return(projectBuilder);
        }