diff --git a/src/Microsoft.DotNet.Compiler.Common/DefaultCompilerWarningSuppresses.cs b/src/Microsoft.DotNet.Compiler.Common/DefaultCompilerWarningSuppresses.cs new file mode 100644 index 000000000..7c430d88e --- /dev/null +++ b/src/Microsoft.DotNet.Compiler.Common/DefaultCompilerWarningSuppresses.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections.Generic; + +namespace Microsoft.DotNet.Cli.Compiler.Common +{ + public class DefaultCompilerWarningSuppresses + { + public static IReadOnlyDictionary> Suppresses { get; } = new Dictionary> + { + { "csc", new string[] {"CS1701", "CS1702", "CS1705" } } + }; + } +} diff --git a/src/Microsoft.DotNet.Compiler.Common/ProjectContextExtensions.cs b/src/Microsoft.DotNet.Compiler.Common/ProjectContextExtensions.cs index fb344de34..f959ac44a 100644 --- a/src/Microsoft.DotNet.Compiler.Common/ProjectContextExtensions.cs +++ b/src/Microsoft.DotNet.Compiler.Common/ProjectContextExtensions.cs @@ -71,7 +71,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common return rootOutputPath; } - + public static void MakeCompilationOutputRunnable(this ProjectContext context, string outputPath, string configuration) { context @@ -115,7 +115,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common targetDirectory = EnsureTrailingSlash(targetDirectory); var pathMap = sourceFiles - .ToDictionary(s => s, + .ToDictionary(s => s, s => Path.Combine(targetDirectory, PathUtility.GetRelativePath(sourceDirectory, s))); @@ -199,5 +199,19 @@ namespace Microsoft.DotNet.Cli.Compiler.Common appConfig.Save(stream); } } + + public static CommonCompilerOptions GetLanguageSpecificCompilerOptions(this ProjectContext context, NuGetFramework framework, string configurationName) + { + var baseOption = context.ProjectFile.GetCompilerOptions(framework, configurationName); + + IReadOnlyList defaultSuppresses; + var compilerName = context.ProjectFile.CompilerName ?? "csc"; + if (DefaultCompilerWarningSuppresses.Suppresses.TryGetValue(compilerName, out defaultSuppresses)) + { + baseOption.SuppressWarnings = (baseOption.SuppressWarnings ?? Enumerable.Empty()).Concat(defaultSuppresses).Distinct(); + } + + return baseOption; + } } } diff --git a/src/Microsoft.DotNet.ProjectModel.Server/InternalModels/ProjectContextSnapshot.cs b/src/Microsoft.DotNet.ProjectModel.Server/InternalModels/ProjectContextSnapshot.cs index ff26a5301..9d2f0702b 100644 --- a/src/Microsoft.DotNet.ProjectModel.Server/InternalModels/ProjectContextSnapshot.cs +++ b/src/Microsoft.DotNet.ProjectModel.Server/InternalModels/ProjectContextSnapshot.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.DotNet.ProjectModel.Server.Helpers; using Microsoft.DotNet.ProjectModel.Server.Models; +using Microsoft.DotNet.Cli.Compiler.Common; using NuGet.Frameworks; namespace Microsoft.DotNet.ProjectModel.Server @@ -62,7 +63,7 @@ namespace Microsoft.DotNet.ProjectModel.Server snapshot.RootDependency = context.ProjectFile.Name; snapshot.TargetFramework = context.TargetFramework; snapshot.SourceFiles = allSourceFiles.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList(); - snapshot.CompilerOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration); + snapshot.CompilerOptions = context.GetLanguageSpecificCompilerOptions(context.TargetFramework, configuration); snapshot.ProjectReferences = allProjectReferences.OrderBy(reference => reference.Name).ToList(); snapshot.FileReferences = allFileReferences.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList(); snapshot.DependencyDiagnostics = allDependencyDiagnostics; diff --git a/src/Microsoft.DotNet.ProjectModel.Server/project.json b/src/Microsoft.DotNet.ProjectModel.Server/project.json index dac5ebe26..0357afd31 100644 --- a/src/Microsoft.DotNet.ProjectModel.Server/project.json +++ b/src/Microsoft.DotNet.ProjectModel.Server/project.json @@ -9,6 +9,7 @@ "System.Threading.ThreadPool": "4.0.10-beta-23704", "System.Runtime.Serialization.Primitives": "4.1.0-rc2-23704", "Microsoft.DotNet.ProjectModel": "1.0.0-*", + "Microsoft.DotNet.Compiler.Common": "1.0.0-*", "Microsoft.Extensions.CommandLineUtils.Sources": { "type": "build", "version": "1.0.0-*" diff --git a/src/Microsoft.DotNet.ProjectModel.Workspaces/ProjectJsonWorkspace.cs b/src/Microsoft.DotNet.ProjectModel.Workspaces/ProjectJsonWorkspace.cs index e779097f2..8560e426e 100644 --- a/src/Microsoft.DotNet.ProjectModel.Workspaces/ProjectJsonWorkspace.cs +++ b/src/Microsoft.DotNet.ProjectModel.Workspaces/ProjectJsonWorkspace.cs @@ -12,7 +12,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Text; -using Microsoft.DotNet.ProjectModel; +using Microsoft.DotNet.Cli.Compiler.Common; using NuGet.Frameworks; namespace Microsoft.DotNet.ProjectModel.Workspaces @@ -68,7 +68,7 @@ namespace Microsoft.DotNet.ProjectModel.Workspaces // TODO: ctor argument? var configuration = "Debug"; - var compilationOptions = project.ProjectFile.GetCompilerOptions(project.TargetFramework, configuration); + var compilationOptions = project.GetLanguageSpecificCompilerOptions(project.TargetFramework, configuration); var compilationSettings = ToCompilationSettings(compilationOptions, project.TargetFramework, project.ProjectFile.ProjectDirectory); @@ -136,7 +136,7 @@ namespace Microsoft.DotNet.ProjectModel.Workspaces _cache[path] = assemblyMetadata; } } - + return assemblyMetadata.GetReference(); } @@ -146,13 +146,8 @@ namespace Microsoft.DotNet.ProjectModel.Workspaces { var options = GetCompilationOptions(compilerOptions, projectDirectory); - // Disable 1702 until roslyn turns this off by default - options = options.WithSpecificDiagnosticOptions(new Dictionary - { - { "CS1701", ReportDiagnostic.Suppress }, // Binding redirects - { "CS1702", ReportDiagnostic.Suppress }, - { "CS1705", ReportDiagnostic.Suppress } - }); + options = options.WithSpecificDiagnosticOptions(compilerOptions.SuppressWarnings.ToDictionary( + suppress => suppress, _ => ReportDiagnostic.Suppress)); AssemblyIdentityComparer assemblyIdentityComparer = targetFramework.IsDesktop() ? @@ -235,4 +230,4 @@ namespace Microsoft.DotNet.ProjectModel.Workspaces public CSharpCompilationOptions CompilationOptions { get; set; } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.DotNet.ProjectModel.Workspaces/project.json b/src/Microsoft.DotNet.ProjectModel.Workspaces/project.json index 777bdf275..49f690287 100644 --- a/src/Microsoft.DotNet.ProjectModel.Workspaces/project.json +++ b/src/Microsoft.DotNet.ProjectModel.Workspaces/project.json @@ -1,16 +1,17 @@ { - "version": "1.0.0-*", - "compilationOptions": { - "keyFile": "../../tools/Key.snk" - }, - "dependencies": { - "NETStandard.Library": "1.0.0-rc2-23704", - "Microsoft.DotNet.ProjectModel": "1.0.0-*", - "Microsoft.CodeAnalysis.CSharp.Workspaces": "1.2.0-beta1-20160108-01" - }, - "frameworks": { - "dnxcore50": { - "imports": "portable-net45+win8" - } + "version": "1.0.0-*", + "compilationOptions": { + "keyFile": "../../tools/Key.snk" + }, + "dependencies": { + "NETStandard.Library": "1.0.0-rc2-23704", + "Microsoft.DotNet.ProjectModel": "1.0.0-*", + "Microsoft.DotNet.Compiler.Common": "1.0.0-*", + "Microsoft.CodeAnalysis.CSharp.Workspaces": "1.2.0-beta1-20160108-01" + }, + "frameworks": { + "dnxcore50": { + "imports": "portable-net45+win8" } + } } diff --git a/src/Microsoft.DotNet.ProjectModel/CommonCompilerOptions.cs b/src/Microsoft.DotNet.ProjectModel/CommonCompilerOptions.cs index c117deef6..4f9f0ccb8 100644 --- a/src/Microsoft.DotNet.ProjectModel/CommonCompilerOptions.cs +++ b/src/Microsoft.DotNet.ProjectModel/CommonCompilerOptions.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; using System.Collections.Generic; using System.Linq; diff --git a/src/Microsoft.DotNet.Tools.Compiler.Csc/Program.cs b/src/Microsoft.DotNet.Tools.Compiler.Csc/Program.cs index 214503bf4..df5248216 100644 --- a/src/Microsoft.DotNet.Tools.Compiler.Csc/Program.cs +++ b/src/Microsoft.DotNet.Tools.Compiler.Csc/Program.cs @@ -124,10 +124,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc ? "-debug:full" : "-debug:portable"); - args.Add("-nowarn:CS1701"); - args.Add("-nowarn:CS1702"); - args.Add("-nowarn:CS1705"); - return args; } diff --git a/src/Microsoft.DotNet.Tools.Compiler/CompilerUtil.cs b/src/Microsoft.DotNet.Tools.Compiler/CompilerUtil.cs index a3ea3b9ca..bc7cc7a75 100644 --- a/src/Microsoft.DotNet.Tools.Compiler/CompilerUtil.cs +++ b/src/Microsoft.DotNet.Tools.Compiler/CompilerUtil.cs @@ -134,7 +134,7 @@ namespace Microsoft.DotNet.Tools.Compiler // used in incremental compilation for the key file public static CommonCompilerOptions ResolveCompilationOptions(ProjectContext context, string configuration) { - var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration); + var compilationOptions = context.GetLanguageSpecificCompilerOptions(context.TargetFramework, configuration); // Path to strong naming key in environment variable overrides path in project.json var environmentKeyFile = Environment.GetEnvironmentVariable(EnvironmentNames.StrongNameKeyFile); diff --git a/src/Microsoft.DotNet.Tools.Compiler/Program.cs b/src/Microsoft.DotNet.Tools.Compiler/Program.cs index 09440b1b1..af465d093 100644 --- a/src/Microsoft.DotNet.Tools.Compiler/Program.cs +++ b/src/Microsoft.DotNet.Tools.Compiler/Program.cs @@ -374,9 +374,6 @@ namespace Microsoft.DotNet.Tools.Compiler .Execute(); } } - - - private static void CopyExport(string outputPath, LibraryExport export) {