Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Xdt module to FAKE 5 #2218

Merged
merged 5 commits into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Fake.sln
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.DotNet.FxCop", "src\ap
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.DotNet.ILMerge", "src\app\Fake.DotNet.ILMerge\Fake.DotNet.ILMerge.fsproj", "{D15BF11A-0426-4053-B6EC-C38B86849240}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.DotNet.Xdt", "src\app\Fake.DotNet.Xdt\Fake.DotNet.Xdt.fsproj", "{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1098,6 +1100,18 @@ Global
{69E4C443-11D6-41BC-920C-ED9D7B36DDCA}.Release|x64.Build.0 = Release|Any CPU
{69E4C443-11D6-41BC-920C-ED9D7B36DDCA}.Release|x86.ActiveCfg = Release|Any CPU
{69E4C443-11D6-41BC-920C-ED9D7B36DDCA}.Release|x86.Build.0 = Release|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Debug|x64.ActiveCfg = Debug|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Debug|x64.Build.0 = Debug|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Debug|x86.ActiveCfg = Debug|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Debug|x86.Build.0 = Debug|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Release|Any CPU.Build.0 = Release|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Release|x64.ActiveCfg = Release|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Release|x64.Build.0 = Release|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Release|x86.ActiveCfg = Release|Any CPU
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1181,6 +1195,7 @@ Global
{3DEF2E95-4BF8-413F-930E-32103A39364A} = {901F162F-8925-4390-89C5-9EE2C343F744}
{D15BF11A-0426-4053-B6EC-C38B86849240} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{69E4C443-11D6-41BC-920C-ED9D7B36DDCA} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{32A8D516-30FA-4DD2-BDA3-F8532CE642D1} = {901F162F-8925-4390-89C5-9EE2C343F744}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {058A0C5E-2216-4306-8AFB-0AE28320C26A}
Expand Down
1 change: 1 addition & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ let dotnetAssemblyInfos =
"Fake.DotNet.Testing.VSTest", "Running vstest test runner"
"Fake.DotNet.Testing.XUnit2", "Running xunit test runner"
"Fake.DotNet.Xamarin", "Running Xamarin builds"
"Fake.DotNet.Xdt", "Running XML Transforms"
"Fake.Installer.InnoSetup", "Creating installers with InnoSetup"
"Fake.Installer.Squirrel", "Squirrel for windows Squirrel.exe tool helper"
"Fake.Installer.Wix", "WiX helper to create msi installers"
Expand Down
1 change: 1 addition & 0 deletions help/templates/template.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<a href="/dotnet-nuget.html" class="navbar-item">NuGet</a>
<a href="/apidocs/v5/fake-dotnet-mage.html" class="navbar-item">Mage</a>
<a href="/apidocs/v5/fake-dotnet-paket.html" class="navbar-item">Paket</a>
<a href="/apidocs/v5/fake-dotnet-xdt.html" class="navbar-item">XML Transforms</a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">
Expand Down
4 changes: 2 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ group netcore
storage: none
framework: net46, net462, netstandard1.6, netstandard2.0, netcoreapp2.0, netcoreapp2.1

nuget DotNet.Xdt
nuget Microsoft.NETCore.App framework: netstandard1.6, netstandard2.0, netcoreapp1.1
nuget FSharp.Compiler.Service storage: packages, content: none
nuget Microsoft.DotNet.PlatformAbstractions ~> 2.0
Expand Down Expand Up @@ -200,5 +201,4 @@ group netcore
nuget System.Runtime.Loader
nuget System.IO.FileSystem.Watcher
nuget System.Data.SqlClient
nuget Microsoft.SqlServer.SqlManagementObjects

nuget Microsoft.SqlServer.SqlManagementObjects
3 changes: 2 additions & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,7 @@ NUGET
FSharp.Core - restriction: || (== net46) (== net462) (&& (== netcoreapp2.0) (< netstandard1.6)) (&& (== netcoreapp2.1) (< netstandard1.6)) (&& (== netstandard2.0) (< netstandard1.6))
FSharp.Core (>= 4.0.1.7-alpha) - restriction: || (&& (== net46) (>= netstandard1.6)) (&& (== net462) (>= netstandard1.6)) (== netcoreapp2.0) (== netcoreapp2.1) (== netstandard1.6) (== netstandard2.0)
NETStandard.Library (>= 1.6) - restriction: || (&& (== net46) (>= netstandard1.6)) (&& (== net462) (>= netstandard1.6)) (== netcoreapp2.0) (== netcoreapp2.1) (== netstandard1.6) (== netstandard2.0)
DotNet.Xdt (2.1)
Expecto (8.6)
Argu (>= 5.1) - restriction: || (&& (== net46) (>= net461)) (&& (== net46) (>= netstandard2.0)) (== net462) (== netcoreapp2.0) (== netcoreapp2.1) (&& (== netstandard1.6) (>= net461)) (&& (== netstandard1.6) (>= netstandard2.0)) (== netstandard2.0)
Mono.Cecil (>= 0.10) - restriction: || (&& (== net46) (>= net461)) (&& (== net46) (>= netstandard2.0)) (== net462) (== netcoreapp2.0) (== netcoreapp2.1) (&& (== netstandard1.6) (>= net461)) (&& (== netstandard1.6) (>= netstandard2.0)) (== netstandard2.0)
Expand Down Expand Up @@ -2086,7 +2087,7 @@ NUGET
Paket.Core (5.193)
Chessie (>= 0.6) - restriction: || (== net46) (== net462) (== netcoreapp2.0) (== netcoreapp2.1) (&& (== netstandard1.6) (>= net45)) (&& (== netstandard1.6) (>= netstandard2.0)) (== netstandard2.0)
FSharp.Compiler.Tools - restriction: || (== net46) (== net462) (&& (== netcoreapp2.0) (>= net45)) (&& (== netcoreapp2.1) (>= net45)) (&& (== netstandard1.6) (>= net45)) (&& (== netstandard2.0) (>= net45))
FSharp.Core (> 4.3) - restriction: || (== net46) (== net462) (&& (== netcoreapp2.0) (>= net45)) (&& (== netcoreapp2.1) (>= net45)) (&& (== netstandard1.6) (>= net45)) (&& (== netstandard2.0) (>= net45))
FSharp.Core (< 4.5) - restriction: || (== net46) (== net462) (&& (== netcoreapp2.0) (>= net45)) (&& (== netcoreapp2.1) (>= net45)) (&& (== netstandard1.6) (>= net45)) (&& (== netstandard2.0) (>= net45))
Mono.Cecil (>= 0.10.0-beta6) - restriction: || (== net46) (== net462) (== netcoreapp2.0) (== netcoreapp2.1) (&& (== netstandard1.6) (>= net45)) (&& (== netstandard1.6) (>= netstandard2.0)) (== netstandard2.0)
Newtonsoft.Json - restriction: || (== net46) (== net462) (&& (== netcoreapp2.0) (>= net45)) (&& (== netcoreapp2.1) (>= net45)) (&& (== netstandard1.6) (>= net45)) (&& (== netstandard2.0) (>= net45))
Newtonsoft.Json (>= 10.0.3) - restriction: || (&& (== net46) (< net45) (>= netstandard2.0)) (&& (== net462) (< net45) (>= netstandard2.0)) (== netcoreapp2.0) (== netcoreapp2.1) (&& (== netstandard1.6) (>= netstandard2.0)) (== netstandard2.0)
Expand Down
17 changes: 17 additions & 0 deletions src/app/Fake.DotNet.Xdt/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("FAKE - F# Make Running XML Transforms")>]
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>]
[<assembly: AssemblyVersionAttribute("5.0.0")>]
[<assembly: AssemblyInformationalVersionAttribute("5.0.0-beta025")>]
[<assembly: AssemblyFileVersionAttribute("5.0.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FAKE - F# Make Running XML Transforms"
let [<Literal>] AssemblyProduct = "FAKE - F# Make"
let [<Literal>] AssemblyVersion = "5.0.0"
let [<Literal>] AssemblyInformationalVersion = "5.0.0-beta025"
let [<Literal>] AssemblyFileVersion = "5.0.0"
25 changes: 25 additions & 0 deletions src/app/Fake.DotNet.Xdt/Fake.DotNet.Xdt.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<DefineConstants>$(DefineConstants);DOTNETCORE</DefineConstants>
<AssemblyName>Fake.DotNet.Xdt</AssemblyName>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Xdt.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fake.Core.Environment\Fake.Core.Environment.fsproj" />
<ProjectReference Include="..\Fake.Core.Trace\Fake.Core.Trace.fsproj" />
<ProjectReference Include="..\Fake.Core.String\Fake.Core.String.fsproj" />
<ProjectReference Include="..\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" />
</ItemGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);FX_NO_SYSTEM_CONFIGURATION;NO_MSBUILD_AVAILABLE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
104 changes: 104 additions & 0 deletions src/app/Fake.DotNet.Xdt/Xdt.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/// Contains functions used to transform config (or any XML) files using Microsoft's XML Document Transformations.
[<RequireQualifiedAccess>]
module Fake.DotNet.Xdt

open System
open System.IO
open System.Xml
open DotNet.Xdt
open Fake.Core

let private xdtTag = KnownTags.Task "XDT"

/// Integrates XDT logging into FAKE logging.
type internal FakeXmlTransformationLogger() =
interface IXmlTransformationLogger with
member x.EndSection(message, messageArgs) =
Trace.log(String.Format(message, messageArgs))
Trace.closeTagUnsafe xdtTag
member x.EndSection(``type``, message, messageArgs) =
match ``type`` with
| MessageType.Verbose ->
Trace.trace(String.Format(message, messageArgs))
Trace.closeTagUnsafe xdtTag
| _ ->
Trace.log(String.Format(message, messageArgs))
Trace.closeTagUnsafe xdtTag

member x.LogError(message, messageArgs) =
Trace.traceError(String.Format(message, messageArgs))

member x.LogError(file, message, messageArgs) =
Trace.traceErrorfn "File: %s" file
Trace.traceError(String.Format(message, messageArgs))

member x.LogError(file, lineNumber, linePosition, message, messageArgs) =
Trace.traceErrorfn "File: %s:%d:%d" file lineNumber linePosition
Trace.traceError(String.Format(message, messageArgs))

member x.LogErrorFromException(ex) =
Trace.traceException ex

member x.LogErrorFromException(ex, file) =
Trace.traceErrorfn "File: %s" file
Trace.traceException ex

member x.LogErrorFromException(ex, file, lineNumber, linePosition) =
Trace.traceErrorfn "File: %s:%d:%d" file lineNumber linePosition
Trace.traceException ex

member x.LogMessage(message, messageArgs) =
Trace.log(String.Format(message, messageArgs))

member x.LogMessage(``type``, message, messageArgs) =
match ``type`` with
| MessageType.Verbose -> Trace.trace(String.Format(message, messageArgs))
| _ -> Trace.log(String.Format(message, messageArgs))

member x.LogWarning(message, messageArgs) =
Trace.traceImportant(String.Format(message, messageArgs))

member x.LogWarning(file, message, messageArgs) =
Trace.traceImportantfn "File: %s" file
Trace.traceImportant(String.Format(message, messageArgs))

member x.LogWarning(file, lineNumber, linePosition, message, messageArgs) =
Trace.traceImportantfn "File: %s:%d:%d" file lineNumber linePosition
Trace.traceImportant(String.Format(message, messageArgs))

member x.StartSection(message, messageArgs) =
Trace.openTagUnsafe xdtTag "StartSection"
Trace.log(String.Format(message, messageArgs))

member x.StartSection(``type``, message, messageArgs) =
match ``type`` with
| MessageType.Verbose ->
Trace.openTagUnsafe xdtTag "StartSectionVerbose"
Trace.trace(String.Format(message, messageArgs))
| _ ->
Trace.openTagUnsafe xdtTag "StartSectionNormal"
Trace.log(String.Format(message, messageArgs))

/// Reads XML file (typically a config file), makes changes according to XDT transform syntax, saves result.
let transformFile (inXmlFile:string) (transformFile:string) (outXmlFile:string) =
if not <| File.Exists inXmlFile then Trace.traceErrorfn "XML file %s does not exist." inXmlFile
if not <| File.Exists transformFile then Trace.traceErrorfn "XML Document Transform file %s does not exist." transformFile
use xdtStream = new FileStream(Path.GetFullPath transformFile, FileMode.Open, FileAccess.Read)
let fakeLogger = new FakeXmlTransformationLogger()
use xdt = new XmlTransformation(xdtStream, fakeLogger)
let xml = new XmlDocument()
xml.Load(Path.GetFullPath inXmlFile)
if not <| xdt.Apply(xml) then new InvalidOperationException(sprintf "Unable to transform %s with %s." inXmlFile transformFile) |> raise
xml.Save(outXmlFile)

/// Modifies an XML file in place using an XDT file named by inserting a .configName in between the filename and .extension.
let transformFileWithConfigName (configName:string) (xmlFile:string) =
let xdt = Path.ChangeExtension(xmlFile, configName + (Path.GetExtension(xmlFile)))
if File.Exists xdt then
transformFile xmlFile xdt xmlFile
else
Trace.traceImportantfn "No %s config file found for '%s'. Skipping." configName xmlFile

/// Modifies XML files in place using an XDT file named by inserting a .configName in between each filename and .extension.
let transformFilesWithConfigName (configName:string) (files:Fake.IO.IGlobbingPattern) =
Seq.iter (transformFileWithConfigName configName) files
4 changes: 4 additions & 0 deletions src/app/Fake.DotNet.Xdt/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
group netcore
FSharp.Core
NETStandard.Library
DotNet.Xdt
Loading