Skip to content

Commit

Permalink
Merge pull request #2098 from fsharp/msbuild_errors
Browse files Browse the repository at this point in the history
Improve Support MSBuild error reporting including the DotNet module
  • Loading branch information
matthid authored Sep 23, 2018
2 parents 1dff9bf + f28e05f commit d85f946
Show file tree
Hide file tree
Showing 26 changed files with 1,111 additions and 576 deletions.
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ do_build:
TERM: "xterm-256color"
MSBUILDDISABLENODEREUSE: "1"
BuildInParallel: "false"
LANG: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8"
LANGUAGE: ""

script: |
export PATH=$PATH:$PWD/fake-dotnetcore/
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: csharp
sudo: required
dist: trusty # Ubuntu 14.04
dotnet : 2.1.302
dotnet : 2.1.402
env:
- HOME=/home/travis APPDATA=/home/travis LocalAppData=/home/travis

Expand Down
13 changes: 10 additions & 3 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Release Notes

## 5.6.2-alpha tbd

* tbd
## 5.7.0-alpha - 2018-09-23

* ENHANCEMENT: Use VSWhere to detect msbuild location - https://github.com/fsharp/FAKE/pull/2077
* ENHANCEMENT: Add Dotnet SDK 2.1.400, 2.1.401 and 2.1.402 - https://github.com/fsharp/FAKE/pull/2089
* ENHANCEMENT: Improve error reporting of msbuild errors across all CI servers - https://github.com/fsharp/FAKE/issues/2096
* ENHANCEMENT: Add /logger support for MSBuild - https://github.com/fsharp/FAKE/issues/1712
* ENHANCEMENT: Add /consoleloggerparameters support for MSBuild - https://github.com/fsharp/FAKE/issues/1607
* ENHANCEMENT: Added `DotNet.msbuild` to call `dotnet msbuild` - https://github.com/fsharp/FAKE/pull/2098
* ENHANCEMENT: Added `MSBuildParams` to `DotNet.restore`, `DotNet.build`, `DotNet.pack`, `DotNet.publish` and `DotNet.test` in order to add regular msbuild parameters - https://github.com/fsharp/FAKE/pull/2098
* ENHANCEMENT: AppVeyor now reports errors and warnings to the 'Messages'-tab - https://github.com/fsharp/FAKE/pull/2098

## 5.6.1 - 2018-09-09

Expand Down
2 changes: 1 addition & 1 deletion build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ let chocoVersion =

Trace.setBuildNumber nugetVersion

let dotnetSdk = lazy DotNet.install DotNet.Versions.Release_2_1_302
let dotnetSdk = lazy DotNet.install DotNet.Versions.FromGlobalJson
let inline dtntWorkDir wd =
DotNet.Options.lift dotnetSdk.Value
>> DotNet.Options.withWorkingDirectory wd
Expand Down
1 change: 1 addition & 0 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DotnetCliToolTargetFramework>netcoreapp2.0</DotnetCliToolTargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk" : {
"version": "2.1.302"
"version": "2.1.402"
}
}
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ group netcore
nuget FSharp.Control.Reactive
nuget System.Reactive.Compatibility
nuget System.Security.Cryptography.Algorithms
nuget MSBuild.StructuredLogger
nuget BlackFox.VsWhere

// Testing
Expand Down
934 changes: 537 additions & 397 deletions paket.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/app/Fake.BuildServer.AppVeyor/AppVeyor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,12 @@ module AppVeyor =
| _ -> ConsoleWriter.writeAnsiColor false color true (sprintf "Starting %s '%s'" tag.Type tag.Name)
| TraceData.CloseTag (tag, time, state) ->
ConsoleWriter.writeAnsiColor false color true (sprintf "Finished (%A) '%s' in %O" state tag.Name time)
| TraceData.ImportantMessage text | TraceData.ErrorMessage text ->
| TraceData.ImportantMessage text ->
ConsoleWriter.writeAnsiColor false color true text
AppVeyorInternal.AddMessage AppVeyorInternal.MessageCategory.Warning "" text
| TraceData.ErrorMessage text ->
ConsoleWriter.writeAnsiColor false color true text
AppVeyorInternal.AddMessage AppVeyorInternal.MessageCategory.Error "" text
| TraceData.LogMessage(text, newLine) | TraceData.TraceMessage(text, newLine) ->
ConsoleWriter.writeAnsiColor false color newLine text
| TraceData.ImportData (ImportData.Nunit NunitDataVersion.Nunit, path) ->
Expand Down
36 changes: 32 additions & 4 deletions src/app/Fake.BuildServer.AppVeyor/AppVeyorInternal.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,44 @@ module internal AppVeyorInternal =
Process.execSimple (fun info ->
{ info with
FileName = "appveyor"
Arguments = args}) (System.TimeSpan.MaxValue)
Arguments = args }) (System.TimeSpan.MaxValue)
|> ignore

let private add msg category =
type MessageCategory =
| Information
| Warning
| Error
| NoCategory
member x.AsString =
match x with
| Information -> Some "Information"
| Warning -> Some "Warning"
| Error -> Some "Error"
| NoCategory -> None

let AddMessage (category:MessageCategory) details msg =
if not <| String.isNullOrEmpty msg then
//let enableProcessTracingPreviousValue = Process.enableProcessTracing
//Process.enableProcessTracing <- false
sprintf "AddMessage %s -Category %s" (Process.quoteIfNeeded msg) (Process.quoteIfNeeded category) |> sendToAppVeyor
try
[ yield "AddMessage"
yield msg
match category.AsString with
| Some cat ->
yield "-Category"
yield cat
| None -> ()
if not (System.String.IsNullOrEmpty details) then
yield "-Details"
yield details ]
|> Args.toWindowsCommandLine
|> sendToAppVeyor
with e ->
// because otherwise there might be recursive failure...
eprintfn "AppVeyor 'AddMessage' failed: %O" e
//sprintf "AddMessage %s -Category %s" (Process.quoteIfNeeded msg) (category.ToString())
//Process.enableProcessTracing <- enableProcessTracingPreviousValue
let private addNoCategory msg = sprintf "AddMessage %s" (Process.quoteIfNeeded msg) |> sendToAppVeyor
//let private addNoCategory msg = sprintf "AddMessage %s" (Process.quoteIfNeeded msg) |> sendToAppVeyor

/// Starts the test case.
let StartTestCase testSuiteName testCaseName =
Expand Down
13 changes: 13 additions & 0 deletions src/app/Fake.Core.Environment/BuildServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ module BuildServer =
/// Is true when the current build is a local build.
let isLocalBuild = LocalBuild = buildServer

let mutable ansiColorSupport =
match buildServer with
| Jenkins -> false
| TeamCity -> true
| CCNet -> false
| Travis -> true
| AppVeyor -> true
| GitLabCI -> true
| TeamFoundation -> false
| Bamboo -> false
| BitbucketPipelines -> false
| LocalBuild -> false


let install (servers: BuildServerInstaller list) =
servers
Expand Down
1 change: 1 addition & 0 deletions src/app/Fake.Core.UserInput/paket.references
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
group netcore

FSharp.Core
NETStandard.Library
121 changes: 105 additions & 16 deletions src/app/Fake.DotNet.Cli/DotNet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,86 @@ module DotNet =
Trace.tracefn ".NET Core SDK installed to %s" exe
(fun opt -> { opt with DotNetCliPath = exe; Version = passVersion})

/// dotnet restore command options
type MSBuildOptions =
{
/// Common tool options
Common: Options
MSBuildParams : MSBuild.CliArguments
}

/// Parameter default values.
static member Create() =
{ Common = Options.Create()
MSBuildParams = MSBuild.CliArguments.Create()
}

/// Gets the current environment
member x.Environment = x.Common.Environment
/// Sets the current environment variables.
member x.WithEnvironment map =
{ x with Common = { x.Common with Environment = map } }

/// Sets a value indicating whether the output for the given process is redirected.
member x.WithRedirectOutput shouldRedirect =
{ x with Common = x.Common.WithRedirectOutput shouldRedirect }

/// Changes the "Common" properties according to the given function
member inline x.WithCommon f =
{ x with Common = f x.Common }

let internal addBinaryLogger disableFakeBinLog args (common:Options) =
// used for detection
let callMsBuildExe args =
let result =
exec (fun _ ->
{ common with
RedirectOutput = true }) "msbuild" args
if not result.OK then
failwithf "msbuild failed with exitcode '%d'" result.ExitCode
String.Join("\n", result.Messages)
MSBuild.addBinaryLogger (common.DotNetCliPath + " msbuild") callMsBuildExe args disableFakeBinLog

let internal execWithBinLog project common command args msBuildArgs =
let argString = MSBuild.fromCliArguments msBuildArgs
let binLogPath, args = addBinaryLogger msBuildArgs.DisableInternalBinLog (args + " " + argString) common
let result = exec (fun _ -> common) command args
MSBuild.handleAfterRun (sprintf "dotnet %s" command) binLogPath result.ExitCode project

/// Runs a MSBuild project
/// ## Parameters
/// - `setParams` - A function that overwrites the default MSBuildOptions
/// - `project` - A string with the path to the project file to build.
///
/// ## Sample
///
/// open Fake.DotNet
/// let setMsBuildParams (defaults:MSBuild.CliArguments) =
/// { defaults with
/// Verbosity = Some(Quiet)
/// Targets = ["Build"]
/// Properties =
/// [
/// "Optimize", "True"
/// "DebugSymbols", "True"
/// "Configuration", "Release"
/// ]
/// }
/// let setParams (defaults:DotNet.MSBuildOptions) =
/// { defaults with
/// MSBuildParams = setMsBuildParams defaults.MSBuildParams
/// }
///
/// DotNet.msbuild setParams "./MySolution.sln"
let msbuild setParams project =
use __ = Trace.traceTask "DotNet:msbuild" project

let param = MSBuildOptions.Create() |> setParams
let args = [project]
let args = Args.toWindowsCommandLine args
execWithBinLog project param.Common "msbuild" args param.MSBuildParams
__.MarkSuccess()

/// dotnet restore command options
type RestoreOptions =
{
Expand All @@ -845,6 +925,8 @@ module DotNet =
IgnoreFailedSources: bool
/// Disables restoring multiple projects in parallel (--disable-parallel)
DisableParallel: bool
/// Other msbuild specific parameters
MSBuildParams : MSBuild.CliArguments
}

/// Parameter default values.
Expand All @@ -857,6 +939,7 @@ module DotNet =
NoCache = false
IgnoreFailedSources = false
DisableParallel = false
MSBuildParams = MSBuild.CliArguments.Create()
}
[<Obsolete("Use Options.Create instead")>]
static member Default = Options.Create()
Expand Down Expand Up @@ -897,17 +980,15 @@ module DotNet =
let restore setParams project =
use __ = Trace.traceTask "DotNet:restore" project
let param = RestoreOptions.Create() |> setParams
let args = project :: buildRestoreArgs param
let result = exec (fun _ -> param.Common) "restore" (Args.toWindowsCommandLine args)
if not result.OK then failwithf "dotnet restore failed with code %i" result.ExitCode
let args = Args.toWindowsCommandLine(project :: buildRestoreArgs param)
execWithBinLog project param.Common "restore" args param.MSBuildParams
__.MarkSuccess()

/// build configuration
type BuildConfiguration =
| Debug
| Release
| Custom of string
with
/// Convert the build configuration to a string that can be passed to the .NET CLI
override this.ToString() =
match this with
Expand Down Expand Up @@ -950,6 +1031,8 @@ module DotNet =
OutputPath: string option
/// No build flag (--no-build)
NoBuild: bool
/// Other msbuild specific parameters
MSBuildParams : MSBuild.CliArguments
}

/// Parameter default values.
Expand All @@ -960,6 +1043,7 @@ module DotNet =
BuildBasePath = None
OutputPath = None
NoBuild = false
MSBuildParams = MSBuild.CliArguments.Create()
}
[<Obsolete("Use PackOptions.Create instead")>]
static member Default = PackOptions.Create()
Expand Down Expand Up @@ -997,9 +1081,8 @@ module DotNet =
let pack setParams project =
use __ = Trace.traceTask "DotNet:pack" project
let param = PackOptions.Create() |> setParams
let args = project :: buildPackArgs param
let result = exec (fun _ -> param.Common) "pack" (Args.toWindowsCommandLine args)
if not result.OK then failwithf "dotnet pack failed with code %i" result.ExitCode
let args = Args.toWindowsCommandLine(project :: buildPackArgs param)
execWithBinLog project param.Common "pack" args param.MSBuildParams
__.MarkSuccess()

/// dotnet publish command options
Expand All @@ -1021,6 +1104,8 @@ module DotNet =
VersionSuffix: string option
/// No build flag (--no-build)
NoBuild: bool
/// Other msbuild specific parameters
MSBuildParams : MSBuild.CliArguments
}

/// Parameter default values.
Expand All @@ -1033,6 +1118,7 @@ module DotNet =
OutputPath = None
VersionSuffix = None
NoBuild = false
MSBuildParams = MSBuild.CliArguments.Create()
}
[<Obsolete("Use PublishOptions.Create instead")>]
static member Default = PublishOptions.Create()
Expand Down Expand Up @@ -1072,9 +1158,8 @@ module DotNet =
let publish setParams project =
use __ = Trace.traceTask "DotNet:publish" project
let param = PublishOptions.Create() |> setParams
let args = project :: buildPublishArgs param
let result = exec (fun _ -> param.Common) "publish" (Args.toWindowsCommandLine args)
if not result.OK then failwithf "dotnet publish failed with code %i" result.ExitCode
let args = Args.toWindowsCommandLine(project :: buildPublishArgs param)
execWithBinLog project param.Common "publish" args param.MSBuildParams
__.MarkSuccess()

/// dotnet build command options
Expand All @@ -1094,6 +1179,8 @@ module DotNet =
OutputPath: string option
/// Native flag (--native)
Native: bool
/// Other msbuild specific parameters
MSBuildParams : MSBuild.CliArguments
}

/// Parameter default values.
Expand All @@ -1105,6 +1192,7 @@ module DotNet =
BuildBasePath = None
OutputPath = None
Native = false
MSBuildParams = MSBuild.CliArguments.Create()
}
[<Obsolete("Use BuildOptions.Create instead")>]
static member Default = BuildOptions.Create()
Expand Down Expand Up @@ -1144,9 +1232,8 @@ module DotNet =
let build setParams project =
use __ = Trace.traceTask "DotNet:build" project
let param = BuildOptions.Create() |> setParams
let args = project :: buildBuildArgs param
let result = exec (fun _ -> param.Common) "build" (Args.toWindowsCommandLine args)
if not result.OK then failwithf "dotnet build failed with code %i" result.ExitCode
let args = Args.toWindowsCommandLine(project :: buildBuildArgs param)
execWithBinLog project param.Common "build" args param.MSBuildParams
__.MarkSuccess()

/// dotnet build command options
Expand Down Expand Up @@ -1187,6 +1274,8 @@ module DotNet =
NoRestore: bool
/// Arguments to pass runsettings configurations through commandline. Arguments may be specified as name-value pair of the form [name]=[value] after "-- ". Note the space after --.
RunSettingsArguments : string option
/// Other msbuild specific parameters
MSBuildParams : MSBuild.CliArguments
}

/// Parameter default values.
Expand All @@ -1206,6 +1295,7 @@ module DotNet =
Collect = None
NoRestore = false
RunSettingsArguments = None
MSBuildParams = MSBuild.CliArguments.Create()
}
[<Obsolete("Use TestOptions.Create instead")>]
static member Default = TestOptions.Create()
Expand Down Expand Up @@ -1251,8 +1341,7 @@ module DotNet =
let test setParams project =
use __ = Trace.traceTask "DotNet:test" project
let param = TestOptions.Create() |> setParams
let args = project :: buildTestArgs param
let result = exec (fun _ -> param.Common) "test" (Args.toWindowsCommandLine args)
if not result.OK then failwithf "dotnet test failed with code %i" result.ExitCode
let args = Args.toWindowsCommandLine(project :: buildTestArgs param)
execWithBinLog project param.Common "test" args param.MSBuildParams
__.MarkSuccess()

Loading

0 comments on commit d85f946

Please sign in to comment.