Skip to content

Commit f8eefdf

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 b521bee commit f8eefdf

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

build/scripts/Paths.fsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
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>
2626
<Prefer32Bit>false</Prefer32Bit>
2727
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
28-
</PropertyGroup>
28+
</PropertyGroup>
2929
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3030
<DebugType>pdbonly</DebugType>
3131
<Optimize>true</Optimize>
3232
<OutputPath>bin\Release\net45\</OutputPath>
33-
<DefineConstants>TRACE;NET45</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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace System.Runtime.CompilerServices
1+
#if NET45
2+
namespace System.Runtime.CompilerServices
23
{
34
internal class FormattableStringFactory
45
{
@@ -34,3 +35,4 @@ public FormattableString(string messageFormat, object[] args)
3435
public string ToString(IFormatProvider formatProvider) => string.Format(formatProvider, _messageFormat, _args);
3536
}
3637
}
38+
#endif

0 commit comments

Comments
 (0)