From d0cda205282ce43f3090a53426d305fdde615b7e Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Fri, 5 Oct 2018 12:32:26 +0200 Subject: [PATCH] use `dotnet msbuild` such that stuff works on teamcity as well. --- .travis.yml | 2 +- global.json | 2 +- src/app/Fake.BuildServer.TeamCity/TeamCity.fs | 2 +- src/app/Fake.DotNet.Cli/DotNet.fs | 25 ++++++++++ .../Fake.DotNet.Cli/Fake.DotNet.Cli.fsproj | 1 + src/app/Fake.DotNet.Cli/VisibleTo.fs | 6 +++ src/app/Fake.DotNet.MSBuild/MSBuild.fs | 37 ++++++++++++++ .../Fake.Core.IntegrationTests.fsproj | 1 + .../Fake.DotNet.MSBuild.fs | 49 +++++-------------- 9 files changed, 86 insertions(+), 39 deletions(-) create mode 100644 src/app/Fake.DotNet.Cli/VisibleTo.fs diff --git a/.travis.yml b/.travis.yml index bf911bc0937..cdaec34f764 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: csharp sudo: required dist: trusty # Ubuntu 14.04 -dotnet : 2.1.402 +dotnet : 2.1.403 env: - HOME=/home/travis APPDATA=/home/travis LocalAppData=/home/travis diff --git a/global.json b/global.json index 666feeb2ba7..b79f7b4d796 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk" : { - "version": "2.1.402" + "version": "2.1.403" } } diff --git a/src/app/Fake.BuildServer.TeamCity/TeamCity.fs b/src/app/Fake.BuildServer.TeamCity/TeamCity.fs index 7e79f5f26d3..144558bc37c 100644 --- a/src/app/Fake.BuildServer.TeamCity/TeamCity.fs +++ b/src/app/Fake.BuildServer.TeamCity/TeamCity.fs @@ -40,7 +40,7 @@ module TeamCityImportExtensions = /// This module does not provide any special APIs please use FAKE APIs and they should integrate into this CI server. /// If some integration is not working as expected or you have features you would like to use directly please open an issue. /// -/// For more information on TeamCity interaction from builc scripts [see here](https://confluence.jetbrains.com/display/TCD18/Build+Script+Interaction+with+TeamCity) +/// For more information on TeamCity interaction from build scripts [see here](https://confluence.jetbrains.com/display/TCD18/Build+Script+Interaction+with+TeamCity) [] module TeamCity = open Fake.IO diff --git a/src/app/Fake.DotNet.Cli/DotNet.fs b/src/app/Fake.DotNet.Cli/DotNet.fs index 099c8025d6d..325d115cee6 100644 --- a/src/app/Fake.DotNet.Cli/DotNet.fs +++ b/src/app/Fake.DotNet.Cli/DotNet.fs @@ -853,6 +853,10 @@ module DotNet = /// Changes the "Common" properties according to the given function member inline x.WithCommon f = { x with Common = f x.Common } + + /// Changes the "MSBuildParams" properties according to the given function + member inline x.WithMSBuildParams f = + { x with MSBuildParams = f x.MSBuildParams } let internal addBinaryLogger disableFakeBinLog args (common:Options) = // used for detection @@ -878,6 +882,15 @@ module DotNet = let result = exec (fun _ -> common) command args MSBuild.handleAfterRun (sprintf "dotnet %s" command) binLogPath result.ExitCode project + let internal tryExecWithBinLog 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 + try + MSBuild.handleAfterRun (sprintf "dotnet %s" command) binLogPath result.ExitCode project + Choice1Of2 result + with e -> Choice2Of2 (e, result) + /// Runs a MSBuild project /// ## Parameters /// - `setParams` - A function that overwrites the default MSBuildOptions @@ -912,6 +925,18 @@ module DotNet = execWithBinLog project param.Common "msbuild" args param.MSBuildParams __.MarkSuccess() + // TODO: Make this API public? change return code? + let internal msbuildWithResult setParams project = + //use __ = Trace.traceTask "DotNet:msbuild" project + + let param = MSBuildOptions.Create() |> setParams + let args = [project] + let args = Args.toWindowsCommandLine args + let r = tryExecWithBinLog project param.Common "msbuild" args param.MSBuildParams + //__.MarkSuccess() + r + + /// dotnet restore command options type RestoreOptions = { diff --git a/src/app/Fake.DotNet.Cli/Fake.DotNet.Cli.fsproj b/src/app/Fake.DotNet.Cli/Fake.DotNet.Cli.fsproj index 9aa5144e51b..c7e118067d3 100644 --- a/src/app/Fake.DotNet.Cli/Fake.DotNet.Cli.fsproj +++ b/src/app/Fake.DotNet.Cli/Fake.DotNet.Cli.fsproj @@ -13,6 +13,7 @@ + diff --git a/src/app/Fake.DotNet.Cli/VisibleTo.fs b/src/app/Fake.DotNet.Cli/VisibleTo.fs new file mode 100644 index 00000000000..21d9c08a2b0 --- /dev/null +++ b/src/app/Fake.DotNet.Cli/VisibleTo.fs @@ -0,0 +1,6 @@ + +namespace System +open System.Runtime.CompilerServices + +[] +do () \ No newline at end of file diff --git a/src/app/Fake.DotNet.MSBuild/MSBuild.fs b/src/app/Fake.DotNet.MSBuild/MSBuild.fs index fa773b67f87..823ead0e2fa 100644 --- a/src/app/Fake.DotNet.MSBuild/MSBuild.fs +++ b/src/app/Fake.DotNet.MSBuild/MSBuild.fs @@ -743,6 +743,43 @@ module MSBuild = let errorMessage = sprintf "'%s %s' failed with exitcode %d." command project exitCode raise (MSBuildException(errorMessage, errors)) + // TODO: Make this API public? Remove "Choice" return value + let internal buildWithRedirect setParams project = + let msBuildParams, argsString = buildArgs setParams + + let args = Process.toParam project + " " + argsString + + // used for detection + let callMsBuildExe args = + let result = + Process.execWithResult (fun info -> + { info with + FileName = msBuildParams.ToolPath + Arguments = args } + |> Process.setEnvironment msBuildParams.Environment) TimeSpan.MaxValue + if not result.OK then + failwithf "msbuild failed with exitcode '%d'" result.ExitCode + String.Join("\n", result.Messages) + + let binlogPath, args = addBinaryLogger msBuildParams.ToolPath callMsBuildExe args msBuildParams.DisableInternalBinLog + let wd = + if msBuildParams.WorkingDirectory = System.IO.Directory.GetCurrentDirectory() + then "" + else sprintf "%s>" msBuildParams.WorkingDirectory + Trace.tracefn "%s%s %s" wd msBuildParams.ToolPath args + + let result = + Process.execWithResult (fun info -> + { info with + FileName = msBuildParams.ToolPath + WorkingDirectory = msBuildParams.WorkingDirectory + Arguments = args } + |> Process.setEnvironment msBuildParams.Environment) TimeSpan.MaxValue + try + handleAfterRun "msbuild" binlogPath result.ExitCode project + Choice1Of2 result + with e -> Choice2Of2 (e, result) + /// Runs a MSBuild project /// ## Parameters diff --git a/src/test/Fake.Core.IntegrationTests/Fake.Core.IntegrationTests.fsproj b/src/test/Fake.Core.IntegrationTests/Fake.Core.IntegrationTests.fsproj index 3b30cc5df7c..4762a414436 100644 --- a/src/test/Fake.Core.IntegrationTests/Fake.Core.IntegrationTests.fsproj +++ b/src/test/Fake.Core.IntegrationTests/Fake.Core.IntegrationTests.fsproj @@ -6,6 +6,7 @@ + diff --git a/src/test/Fake.Core.IntegrationTests/Fake.DotNet.MSBuild.fs b/src/test/Fake.Core.IntegrationTests/Fake.DotNet.MSBuild.fs index 5372d86ab64..d155fe20b8a 100644 --- a/src/test/Fake.Core.IntegrationTests/Fake.DotNet.MSBuild.fs +++ b/src/test/Fake.Core.IntegrationTests/Fake.DotNet.MSBuild.fs @@ -5,45 +5,19 @@ open Fake.Core open Fake.DotNet open Expecto -let buildWithRedirect setParams project = - let msBuildParams, argsString = MSBuild.buildArgs setParams +// Use `dotnet msbuild` for now as it will be the same version across all CI servers +let dotnetSdk = lazy DotNet.install DotNet.Versions.FromGlobalJson - let args = Process.toParam project + " " + argsString +let inline opts () = DotNet.Options.lift dotnetSdk.Value - // used for detection - let callMsBuildExe args = - let result = - Process.execWithResult (fun info -> - { info with - FileName = msBuildParams.ToolPath - Arguments = args } - |> Process.setEnvironment msBuildParams.Environment) TimeSpan.MaxValue - if not result.OK then - failwithf "msbuild failed with exitcode '%d'" result.ExitCode - String.Join("\n", result.Messages) - - let binlogPath, args = MSBuild.addBinaryLogger msBuildParams.ToolPath callMsBuildExe args msBuildParams.DisableInternalBinLog - let wd = - if msBuildParams.WorkingDirectory = System.IO.Directory.GetCurrentDirectory() - then "" - else sprintf "%s>" msBuildParams.WorkingDirectory - Trace.tracefn "%s%s %s" wd msBuildParams.ToolPath args - - let result = - Process.execWithResult (fun info -> - { info with - FileName = msBuildParams.ToolPath - WorkingDirectory = msBuildParams.WorkingDirectory - Arguments = args } - |> Process.setEnvironment msBuildParams.Environment) TimeSpan.MaxValue - try - MSBuild.handleAfterRun "msbuild" binlogPath result.ExitCode project - Choice1Of2 result - with e -> Choice2Of2 (e, result) +let inline dtntWorkDir wd = + DotNet.Options.lift dotnetSdk.Value + >> DotNet.Options.withWorkingDirectory wd + >> DotNet.Options.withRedirectOutput true let simplePropertyTest propValue = let dllPath = System.IO.Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly().Location) - let setParams (defaults:MSBuildParams) = + let setMSBuildParams (defaults:MSBuild.CliArguments) = { defaults with Verbosity = Some(MSBuildVerbosity.Minimal) Targets = ["Test"] @@ -52,10 +26,13 @@ let simplePropertyTest propValue = [ "Property1", propValue ] - WorkingDirectory = dllPath } + let setParams (p:DotNet.MSBuildOptions) = + p.WithMSBuildParams setMSBuildParams + |> dtntWorkDir dllPath + - match buildWithRedirect setParams "testdata/testProperty.proj" with + match DotNet.msbuildWithResult setParams "testdata/testProperty.proj" with | Choice1Of2 result -> let lines = String.Join("\n", result.Results |> Seq.map (fun r -> r.Message)) if Environment.isWindows then