コード例 #1
0
        public void CombiningWithOtherOptionsOverwrites()
        {
            var options = new CompilerOptions
            {
                AllowUnsafe      = false,
                Optimize         = true,
                WarningsAsErrors = true,
                LanguageVersion  = "x",
                DebugSymbols     = "foo"
            };

            var options2 = new CompilerOptions
            {
                AllowUnsafe      = true,
                Optimize         = false,
                WarningsAsErrors = false,
                LanguageVersion  = "y",
                DebugSymbols     = "foo2",
            };

            var result = CompilerOptions.Combine(options, options2);

            Assert.True(result.AllowUnsafe.Value);
            Assert.False(result.Optimize.Value);
            Assert.False(result.WarningsAsErrors.Value);
            Assert.Equal("y", result.LanguageVersion);
            Assert.Equal("foo2", result.DebugSymbols);
        }
コード例 #2
0
        public void CombiningWithNullSkipsNulls()
        {
            var options = new CompilerOptions
            {
                Optimize = true
            };

            var result = CompilerOptions.Combine(options, null);

            Assert.True(result.Optimize.Value);
        }
コード例 #3
0
        public static CompilationSettings GetCompilationSettings(this Project project, FrameworkName targetFramework, string configuration)
        {
            // Get all project options and combine them
            var rootOptions            = project.GetCompilerOptions();
            var configurationOptions   = project.GetCompilerOptions(configuration);
            var targetFrameworkOptions = project.GetCompilerOptions(targetFramework);

            // Combine all of the options
            var resultOptions = CompilerOptions.Combine(rootOptions, configurationOptions, targetFrameworkOptions);

            var options = GetCompilationOptions(resultOptions);

            // Disable 1702 until roslyn turns this off by default
            options = options.WithSpecificDiagnosticOptions(new Dictionary <string, ReportDiagnostic>
            {
                { "CS1702", ReportDiagnostic.Suppress },
                { "CS1705", ReportDiagnostic.Suppress }
            });

            if (PlatformHelper.IsMono)
            {
                options = options.WithConcurrentBuild(concurrentBuild: false);
            }

            AssemblyIdentityComparer assemblyIdentityComparer =
#if ASPNET50
                VersionUtility.IsDesktop(targetFramework) ?
                DesktopAssemblyIdentityComparer.Default :
#endif
                null;

            options = options.WithAssemblyIdentityComparer(assemblyIdentityComparer);

            LanguageVersion languageVersion;

            if (!Enum.TryParse <LanguageVersion>(value: resultOptions.LanguageVersion,
                                                 ignoreCase: true,
                                                 result: out languageVersion))
            {
                languageVersion = LanguageVersion.CSharp6;
            }

            var settings = new CompilationSettings
            {
                LanguageVersion    = languageVersion,
                Defines            = resultOptions.Defines ?? Enumerable.Empty <string>(),
                CompilationOptions = options
            };

            return(settings);
        }
コード例 #4
0
        public void CombiningConcatsDefines()
        {
            var options = new CompilerOptions
            {
                Defines = new[] { "OPT1" }
            };

            var options2 = new CompilerOptions
            {
                Defines = new[] { "OPT2" }
            };

            var result = CompilerOptions.Combine(options, options2);

            Assert.Equal(new[] { "OPT1", "OPT2" }, result.Defines);
        }
コード例 #5
0
        public void TestMethod1()
        {
            string[] dlls = new string[6] {
                @"C:\Temp\Test.dll", @"c:\temp\test.dll", @"c:\temp\a.dll", @"Microsoft.Text.dll",
                @"JohnsHope.Excel.dll", @"c:\temp\b.dll"
            };

            CompilerOptions.PackagedAssembly a = new CompilerOptions.PackagedAssembly(@"C:\Temp\test.dll");

            CompilerOptions o = new CompilerOptions(), n = new CompilerOptions();

            n.PackagedImports.AddRange(dlls);
            n.Imports.AddRange(dlls);

            o.Combine(n);
        }