-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b389da
commit ec7d60a
Showing
10 changed files
with
230 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/// 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 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 | ||
|
||
/// Reads XML file (typically a config file), makes changes according to XDT transform syntax, saves result. | ||
[<System.Obsolete("Please use transformFile instead.")>] | ||
let TransformFile (inXmlFile:string) (transformFileName:string) (outXmlFile:string) = | ||
transformFile inXmlFile transformFileName outXmlFile | ||
|
||
/// Modifies an XML file in place using an XDT file named by inserting a .configName in between the filename and .extension. | ||
[<System.Obsolete("Please use transformFileWithConfigName instead.")>] | ||
let TransformFileWithConfigName (configName:string) (xmlFile:string) = | ||
transformFileWithConfigName configName xmlFile | ||
|
||
/// Modifies XML files in place using an XDT file named by inserting a .configName in between each filename and .extension. | ||
[<System.Obsolete("Please use transformFilesWithConfigName instead.")>] | ||
let TransformFilesWithConfigName (configName:string) (files:Fake.IO.IGlobbingPattern) = | ||
transformFilesWithConfigName configName files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
group netcore | ||
FSharp.Core | ||
NETStandard.Library | ||
DotNet.Xdt |
Oops, something went wrong.