我正在尝试检索设置 TreatWarningsAsErrors,但无法为我加载的解决方案的项目找到它。
我想要完成的是从项目文件中获取设置,并将其设置为true
,如果还没有的话。接下来,我想让 Roslyn 使用新设置进行编译,这样我就可以检查这是否会破坏项目。
我看过很多地方,其中包括Project.CompilationOptions
。项目构建的大多数选项都在那里,除了这个。
The CompilationOptions http://source.roslyn.io/#Microsoft.CodeAnalysis/Compilation/CompilationOptions.cs包含所有构建设置,例如警告级别等。但是TreatWarningsAsErrors
不在这里。我是不是看错地方了?
我打开解决方案的方式类似于FormatSolution sample https://github.com/dotnet/roslyn/tree/master/src/Samples/CSharp/FormatSolution:
var solutionFile = @"C:\ties\src\playground\EnforceTreatAllWarningsAsErrors\EnforceTreatAllWarningsAsErrors.sln";
var workspace = MSBuildWorkspace.Create();
var solution = workspace.OpenSolutionAsync(solutionFile).Result;
var project = solution.Projects.Single();
// warning level is there
var warningLevel = project.CompilationOptions.WarningLevel;
// treat warnings as errors is not there... The following doesn't compile :(
bool treatWarningsAsErrors = project.CompilationOptions.TreatWarningsAsErrors;
您正在寻找
compilationOptions.WithGeneralDiagnosticOption(ReportDiagnostic.Error)
Source http://source.roslyn.io/#Microsoft.CodeAnalysis.CSharp.Workspaces/LanguageServices/CSharpHostBuildDataFactory.cs,173
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)