2

I'm building a project with a .fsx script using FAKE and MSBuild. When building with MSBuild, i give it several parameters:

Target "BuildProject" (fun _ ->
CleanDir ProjectDir
[ProjectPath]
|> MSBuild ProjectDir "Build" ["Configuration", "Release"; "Platform","x64"; "Verbosity", "quiet"; "TreatWarningsAsErrors", "true"]
|> ignore)

However, when i run my script, warnings are not treated as errors:

Build succeeded.

1 Warning(s)
0 Error(s)

Time Elapsed 00:00:11.36
Finished Target: BuildProject

Here is my commandline input:

Building project: MyProject/MyProject.fsproj
  C:\Program Files (x86)\Microsoft Visual 
Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe  
MyProject/MyProject.fsproj /t:Build /m  /nodeReuse:False /p:RestorePackages="False" 
/p:OutputPath="D:\MyProjectFolder\build\MyProject" /p:Configuration="Release" /p:Platform="x64" 
/p:Verbosity="quiet" /p:TreatWarningsAsErrors="true" /logger:Fake.MsBuildLogger+ErrorLogger,"D:\MyProjectFolder\Project\packages\FAKE\tools\FakeLib.dll"

I'm not sure if the property is set correctly, but i've tried various versions by reading the documentation of FAKE and MSBuild.

From what i've read online, the property has to be given to the compiler, and will not work if the property is defined in a XML file.

Im using FAKE 4.64.11.

I want all warnings to be treated as errors, and not just specific warnings.

Hope someone can help.

mbx
  • 6,292
  • 6
  • 58
  • 91
Hobitten
  • 101
  • 7
  • 1
    To put more information, I have tried to ignore warnings but no luck. Seems the solution to this question might be useful for me. – Nghia Bui May 20 '19 at 16:53
  • 1
    Is this an MSBuild Warning or an F# Compiler Warning? Does the number start "MSB%" or "FS%"? – DaveShaw May 20 '19 at 20:33
  • Its a MSBuild warning: "MSB3245". In this case just a missing package that i deleted to force the warning. – Hobitten May 21 '19 at 13:45

1 Answers1

1

So... after reasearching a bit further, it seems that MSB errors such as missing assemblys, cannot be caught by the TreatWarningsAsErrors-approach as i stated above. A way to get around this, is by having a custom build-wrapper that catches these errors.

I found the answer in the answer to this question: Treat all warnings as errors

Another similar thread: How can I treat MSB3245 (could not resolve reference) warning as an error?

Hobitten
  • 101
  • 7