Skip to content

Commit

Permalink
use dotnet msbuild such that stuff works on teamcity as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed Oct 5, 2018
1 parent 2969411 commit d0cda20
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 39 deletions.
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.402
dotnet : 2.1.403
env:
- HOME=/home/travis APPDATA=/home/travis LocalAppData=/home/travis

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.402"
"version": "2.1.403"
}
}
2 changes: 1 addition & 1 deletion src/app/Fake.BuildServer.TeamCity/TeamCity.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
[<RequireQualifiedAccess>]
module TeamCity =
open Fake.IO
Expand Down
25 changes: 25 additions & 0 deletions src/app/Fake.DotNet.Cli/DotNet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 =
{
Expand Down
1 change: 1 addition & 0 deletions src/app/Fake.DotNet.Cli/Fake.DotNet.Cli.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="VisibleTo.fs" />
<Compile Include="DotNet.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/app/Fake.DotNet.Cli/VisibleTo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

namespace System
open System.Runtime.CompilerServices

[<assembly: InternalsVisibleTo("Fake.Core.IntegrationTests")>]
do ()
37 changes: 37 additions & 0 deletions src/app/Fake.DotNet.MSBuild/MSBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ItemGroup>
<ProjectReference Include="..\..\app\Fake.Core.Process\Fake.Core.Process.fsproj" />
<ProjectReference Include="..\..\app\Fake.DotNet.MSBuild\Fake.DotNet.MSBuild.fsproj" />
<ProjectReference Include="..\..\app\Fake.DotNet.Cli\Fake.DotNet.Cli.fsproj" />
<ProjectReference Include="..\..\app\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" />
<ProjectReference Include="..\..\app\Fake.Runtime\Fake.Runtime.fsproj" />
</ItemGroup>
Expand Down
49 changes: 13 additions & 36 deletions src/test/Fake.Core.IntegrationTests/Fake.DotNet.MSBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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
Expand Down

0 comments on commit d0cda20

Please sign in to comment.