예제 #1
0
        private static CommonCompilerOptions GetCompilationOptions(JObject rawObject, Project project)
        {
            var compilerName = rawObject.Value <string>("compilerName");

            if (compilerName != null)
            {
                var lineInfo = rawObject.Value <IJsonLineInfo>("compilerName");
                project.Diagnostics.Add(
                    new DiagnosticMessage(
                        ErrorCodes.DOTNET1016,
                        $"The 'compilerName' option in the root is deprecated. Use it in 'buildOptions' instead.",
                        project.ProjectFilePath,
                        DiagnosticMessageSeverity.Warning,
                        lineInfo.LineNumber,
                        lineInfo.LinePosition));
            }

            var rawOptions = rawObject.Value <JToken>("buildOptions") as JObject;

            if (rawOptions == null)
            {
                rawOptions = rawObject.Value <JToken>("compilationOptions") as JObject;
                if (rawOptions == null)
                {
                    return(new CommonCompilerOptions
                    {
                        CompilerName = compilerName ?? "csc"
                    });
                }

                var lineInfo = (IJsonLineInfo)rawOptions;

                project.Diagnostics.Add(
                    new DiagnosticMessage(
                        ErrorCodes.DOTNET1015,
                        $"The 'compilationOptions' option is deprecated. Use 'buildOptions' instead.",
                        project.ProjectFilePath,
                        DiagnosticMessageSeverity.Warning,
                        lineInfo.LineNumber,
                        lineInfo.LinePosition));
            }

            var analyzerOptionsJson = rawOptions.Value <JToken>("analyzerOptions") as JObject;

            if (analyzerOptionsJson != null)
            {
                var analyzerOptions = new AnalyzerOptions();

                foreach (var analyzerOption in analyzerOptionsJson)
                {
                    switch (analyzerOption.Key)
                    {
                    case "languageId":
                        if (analyzerOption.Value.Type != JTokenType.String)
                        {
                            throw FileFormatException.Create(
                                      "The analyzer languageId must be a string",
                                      analyzerOption.Value.ToString(),
                                      project.ProjectFilePath);
                        }
                        analyzerOptions = new AnalyzerOptions(analyzerOption.Value.ToString());
                        break;

                    default:
                        throw FileFormatException.Create(
                                  $"Unrecognized analyzerOption key: {analyzerOption.Key}",
                                  project.ProjectFilePath);
                    }
                }

                project.AnalyzerOptions = analyzerOptions;
            }

            return(new CommonCompilerOptions
            {
                Defines = rawOptions.Value <JToken>("define")?.Values <string>().ToArray(),
                SuppressWarnings = rawOptions.Value <JToken>("nowarn")?.Values <string>().ToArray(),
                AdditionalArguments = rawOptions.Value <JToken>("additionalArguments")?.Values <string>().ToArray(),
                LanguageVersion = rawOptions.Value <string>("languageVersion"),
                AllowUnsafe = rawOptions.Value <bool?>("allowUnsafe"),
                Platform = rawOptions.Value <string>("platform"),
                WarningsAsErrors = rawOptions.Value <bool?>("warningsAsErrors"),
                Optimize = rawOptions.Value <bool?>("optimize"),
                KeyFile = rawOptions.Value <string>("keyFile"),
                DelaySign = rawOptions.Value <bool?>("delaySign"),
                PublicSign = rawOptions.Value <bool?>("publicSign"),
                DebugType = rawOptions.Value <string>("debugType"),
                EmitEntryPoint = rawOptions.Value <bool?>("emitEntryPoint"),
                GenerateXmlDocumentation = rawOptions.Value <bool?>("xmlDoc"),
                PreserveCompilationContext = rawOptions.Value <bool?>("preserveCompilationContext"),
                OutputName = rawOptions.Value <string>("outputName"),
                CompilerName = rawOptions.Value <string>("compilerName") ?? compilerName ?? "csc",
                CompileInclude = GetIncludeContext(
                    project,
                    rawOptions,
                    "compile",
                    defaultBuiltInInclude: ProjectFilesCollection.DefaultCompileBuiltInPatterns,
                    defaultBuiltInExclude: ProjectFilesCollection.DefaultBuiltInExcludePatterns),
                EmbedInclude = GetIncludeContext(
                    project,
                    rawOptions,
                    "embed",
                    defaultBuiltInInclude: ProjectFilesCollection.DefaultResourcesBuiltInPatterns,
                    defaultBuiltInExclude: ProjectFilesCollection.DefaultBuiltInExcludePatterns),
                CopyToOutputInclude = GetIncludeContext(
                    project,
                    rawOptions,
                    "copyToOutput",
                    defaultBuiltInInclude: null,
                    defaultBuiltInExclude: ProjectFilesCollection.DefaultPublishExcludePatterns)
            });
        }
예제 #2
0
파일: ProjectReader.cs 프로젝트: marono/cli
        private static CommonCompilerOptions GetCompilationOptions(JsonObject rawObject, Project project)
        {
            var rawOptions = rawObject.ValueAsJsonObject("compilationOptions");
            if (rawOptions == null)
            {
                return null;
            }

            var analyzerOptionsJson = rawOptions.Value("analyzerOptions") as JsonObject;
            if (analyzerOptionsJson != null)
            {
                var analyzerOptions = new AnalyzerOptions();

                foreach (var key in analyzerOptionsJson.Keys)
                {
                    switch (key)
                    {
                        case "languageId":
                            var languageId = analyzerOptionsJson.ValueAsString(key);
                            if (languageId == null)
                            {
                                throw FileFormatException.Create(
                                    "The analyzer languageId must be a string",
                                    analyzerOptionsJson.Value(key),
                                    project.ProjectFilePath);
                            }
                            analyzerOptions.LanguageId = languageId;
                            break;

                        default:;
                            throw FileFormatException.Create(
                               $"Unrecognized analyzerOption key: {key}",
                               project.ProjectFilePath);
                    }
                }

                project.AnalyzerOptions = analyzerOptions;
            }

            return new CommonCompilerOptions
            {
                Defines = rawOptions.ValueAsStringArray("define"),
                SuppressWarnings = rawOptions.ValueAsStringArray("nowarn"),
                AdditionalArguments = rawOptions.ValueAsStringArray("additionalArguments"),
                LanguageVersion = rawOptions.ValueAsString("languageVersion"),
                AllowUnsafe = rawOptions.ValueAsNullableBoolean("allowUnsafe"),
                Platform = rawOptions.ValueAsString("platform"),
                WarningsAsErrors = rawOptions.ValueAsNullableBoolean("warningsAsErrors"),
                Optimize = rawOptions.ValueAsNullableBoolean("optimize"),
                KeyFile = rawOptions.ValueAsString("keyFile"),
                DelaySign = rawOptions.ValueAsNullableBoolean("delaySign"),
                PublicSign = rawOptions.ValueAsNullableBoolean("publicSign"),
                EmitEntryPoint = rawOptions.ValueAsNullableBoolean("emitEntryPoint"),
                GenerateXmlDocumentation = rawOptions.ValueAsNullableBoolean("xmlDoc"),
                PreserveCompilationContext = rawOptions.ValueAsNullableBoolean("preserveCompilationContext")
            };
        }
예제 #3
0
파일: ProjectReader.cs 프로젝트: nosoq/cli
        private static CommonCompilerOptions GetCompilationOptions(JsonObject rawObject, Project project)
        {
            var rawOptions = rawObject.ValueAsJsonObject("compilationOptions");

            if (rawOptions == null)
            {
                return(null);
            }

            var analyzerOptionsJson = rawOptions.Value("analyzerOptions") as JsonObject;

            if (analyzerOptionsJson != null)
            {
                var analyzerOptions = new AnalyzerOptions();

                foreach (var key in analyzerOptionsJson.Keys)
                {
                    switch (key)
                    {
                    case "languageId":
                        var languageId = analyzerOptionsJson.ValueAsString(key);
                        if (languageId == null)
                        {
                            throw FileFormatException.Create(
                                      "The analyzer languageId must be a string",
                                      analyzerOptionsJson.Value(key),
                                      project.ProjectFilePath);
                        }
                        analyzerOptions.LanguageId = languageId;
                        break;

                    default:
                        ;
                        throw FileFormatException.Create(
                                  $"Unrecognized analyzerOption key: {key}",
                                  project.ProjectFilePath);
                    }
                }

                project.AnalyzerOptions = analyzerOptions;
            }

            return(new CommonCompilerOptions
            {
                Defines = rawOptions.ValueAsStringArray("define"),
                SuppressWarnings = rawOptions.ValueAsStringArray("nowarn"),
                AdditionalArguments = rawOptions.ValueAsStringArray("additionalArguments"),
                LanguageVersion = rawOptions.ValueAsString("languageVersion"),
                AllowUnsafe = rawOptions.ValueAsNullableBoolean("allowUnsafe"),
                Platform = rawOptions.ValueAsString("platform"),
                WarningsAsErrors = rawOptions.ValueAsNullableBoolean("warningsAsErrors"),
                Optimize = rawOptions.ValueAsNullableBoolean("optimize"),
                KeyFile = rawOptions.ValueAsString("keyFile"),
                DelaySign = rawOptions.ValueAsNullableBoolean("delaySign"),
                PublicSign = rawOptions.ValueAsNullableBoolean("publicSign"),
                DebugType = rawOptions.ValueAsString("debugType"),
                EmitEntryPoint = rawOptions.ValueAsNullableBoolean("emitEntryPoint"),
                GenerateXmlDocumentation = rawOptions.ValueAsNullableBoolean("xmlDoc"),
                PreserveCompilationContext = rawOptions.ValueAsNullableBoolean("preserveCompilationContext")
            });
        }