Skip to content

Commit 56d0a63

Browse files
committed
Pass constants when building with MSBuild
FormattableString only needs to included when building .NET 4.5 so allow defining of constants when building from command line with MSBuild
1 parent 9ba9dae commit 56d0a63

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

build/scripts/Paths.fsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ module Tooling =
132132
let targetLocation = "build/tools/nuget/nuget.exe"
133133
if (not (File.Exists targetLocation))
134134
then
135-
trace "Nuget not found %s. Downloading now"
135+
trace (sprintf "Nuget not found at %s. Downloading now" targetLocation)
136136
let url = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
137137
Directory.CreateDirectory("build/tools/nuget") |> ignore
138138
use webClient = new WebClient()
@@ -209,16 +209,16 @@ module Tooling =
209209

210210
let DotNet = new DotNetTooling("dotnet.exe")
211211

212-
type DotNetFrameworkIdentifier = { MSBuild: string; Nuget: string; }
212+
type DotNetFrameworkIdentifier = { MSBuild: string; Nuget: string; DefineConstants: string; }
213213

214214
type DotNetFramework =
215215
| Net45
216216
| Net46
217217
static member All = [Net45; Net46]
218218
member this.Identifier =
219219
match this with
220-
| Net45 -> { MSBuild = "v4.5"; Nuget = "net45"; }
221-
| Net46 -> { MSBuild = "v4.6"; Nuget = "net46"; }
220+
| Net45 -> { MSBuild = "v4.5"; Nuget = "net45"; DefineConstants = "TRACE;NET45"; }
221+
| Net46 -> { MSBuild = "v4.6"; Nuget = "net46"; DefineConstants = "TRACE;NET46"; }
222222

223223
type MsBuildTooling() =
224224
let msbuildProperties = [
@@ -227,6 +227,11 @@ module Tooling =
227227
]
228228

229229
member this.Exec output target framework projects =
230-
MSBuild output target (msbuildProperties |> List.append [("TargetFrameworkVersion", framework.MSBuild)]) projects |> ignore
230+
let properties = msbuildProperties
231+
|> List.append [
232+
("TargetFrameworkVersion", framework.MSBuild);
233+
("DefineConstants", framework.DefineConstants)
234+
]
235+
MSBuild output target properties projects |> ignore
231236

232237
let MsBuild = new MsBuildTooling()

src/Elasticsearch.Net/Elasticsearch.Net.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<DebugType>full</DebugType>
2020
<Optimize>false</Optimize>
2121
<OutputPath>bin\Debug\net45\</OutputPath>
22-
<DefineConstants>TRACE;DEBUG</DefineConstants>
22+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG</DefineConstants>
2323
<ErrorReport>prompt</ErrorReport>
2424
<WarningLevel>4</WarningLevel>
2525
<UseVSHostingProcess>false</UseVSHostingProcess>
@@ -30,7 +30,7 @@
3030
<DebugType>pdbonly</DebugType>
3131
<Optimize>true</Optimize>
3232
<OutputPath>bin\Release\net45\</OutputPath>
33-
<DefineConstants>TRACE</DefineConstants>
33+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE</DefineConstants>
3434
<ErrorReport>prompt</ErrorReport>
3535
<WarningLevel>4</WarningLevel>
3636
<DocumentationFile>bin\Release\net45\Elasticsearch.Net.XML</DocumentationFile>

src/Elasticsearch.Net/Extensions/FormattableString.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
#if NET45
22
namespace System.Runtime.CompilerServices
33
{
44
internal class FormattableStringFactory
@@ -35,3 +35,4 @@ public FormattableString(string messageFormat, object[] args)
3535
public string ToString(IFormatProvider formatProvider) => string.Format(formatProvider, _messageFormat, _args);
3636
}
3737
}
38+
#endif

0 commit comments

Comments
 (0)