Git Product home page Git Product logo

magic-chunks-dotnetcore's Introduction

AppVeyor Github Releases NuGet Visual Studio Marketplace

Magic Chunks

Easy to use tool to config transformations for JSON, XML and YAML.


Everyone remember XML Document Transform syntax to transform configuration files during the build process. But world is changing and now you can have different config types in your .NET projects.

Magic Chunks allows you to transform you JSON, XML and YAML files. You can run it at MSBuild, Cake, PSake or Powershell script as well as use Visual Studio Team Services build extension. Also, it's possible to reference Magic Chunks from your .NET projects in more complicated cases.

How it works

The main idea is quite simple. Magic Chunks represents transformation as a key-value collection.

The key contains path in the source file which should be modified, and the value contains data for this path in modified file.

If you are using Magic Chunks from .NET or Cake, you can also pass in any keys to be removed into the constructor.

XML

Imagine you have following XML based configuration file.

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5.1" />
    <authentication mode="None" />
  </system.web>
</configuration>

So following transformations could be applied to this config:

{
  "configuration/system.web/compilation/@debug": "false",
  "configuration/system.web/authentication/@mode": "Forms"
}

As a result you will have config like this:

<configuration>
  <system.web>
    <compilation debug="false" targetFramework="4.5.1" />
    <authentication mode="Forms" />
  </system.web>
</configuration>

JSON

The same approach works if you have JSON based configuration:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=webapp"
  }
}

Transformation for the config could be:

{
  "ConnectionStrings/DefaultConnection": "Data Source=10.0.0.5;Initial Catalog=Db1;Persist Security Info=True"
}

After transformation you will have:

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=10.0.0.5;Initial Catalog=Db1;Persist Security Info=True"
  }
}

Supported formats

Magic Chunks supports following file formats:

  1. XML
  2. JSON
  3. YAML

Getting started

Let's say you have appsettings.json file at C:\sources\project1 folder:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=webapp"
  }
}

To use Magic Chunks download latest release manually or get it directly from Nuget.

For example we will use Powershell to transform configuration file. To do this you have to write something like this:

Import-Module .\MagicChunks.psm1

Format-MagicChunks -path C:\sources\project1\appsettings.json -transformations @{
 "ConnectionStrings/DefaultConnection" = "Data Source=10.0.0.5;Initial Catalog=Db1;Persist Security Info=True"
}

To transform config files you can use any approach you like:

To learn more check wiki page.

Maintainers

Contributions

Any contributions are welcome. Most probably someone will want to extend it with additional formats. So feel free to make pull requests for your changes. Read contribution guidelines to start.

License

Magic Chunks is released under the MIT License.

magic-chunks-dotnetcore's People

Contributors

droyad avatar gep13 avatar ikaew avatar jamie-clayton avatar nils-a avatar pascalberger avatar sergeyzwezdin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magic-chunks-dotnetcore's Issues

Delete node

Hello,
I would like to know if there is an existing syntax to delete a node:

<root>
   <node1>Value</node1>
</root>

--> I'd like to delete <node1>Value</node1>

Thank you,
Antoine

Using deprecated version of YamlDotNet deserializer configurator

Building the current version gives this deprecation warning:

'Deserializer.Deserializer(IObjectFactory, INamingConvention, bool, YamlAttributeOverrides)' is obsolete: 'Please use DeserializerBuilder to customize the Deserializer. This constructor will be removed in future releases.'

Help: how to change an "add" and how to delete

I have an app.config file. It has many "add" entries in the "appSettings" section.

Using your tool, it is easy to add a key with a particular value.

But how do I target a particular "add", such as the fourth one in the list?

Example:
<add key="MaxConcurrentAutoVueControls" value="3" />

If I add, I then have two keys, one with the proper setting. The fourth one on the list is still in the appSettings set with unchanged values.

Is it possible to delete a particular key with your tool?

I know how to do it using other techniques.

JSON arrays

Is it possible to replace multiple values in a json array?

Example:

{
  "bindings": [
    {
      "type": "httpTrigger",
      "direction": "in",
      "webHookType": "genericJson",
      "name": "req"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "blob",
      "name": "name2",
      "path": "path2",
      "connection": "connection_storage",
      "direction": "in"
    },
    {
      "type": "blob",
      "name": "name2",
      "path": "path2",
      "connection": "connection_storage",
      "direction": "in"
    }
  ],
  "disabled": false
}

In this json file i want to replace the connection attribute of all elements in the bindings array.

I tried this
Transformation file:

{
  "bindings/connection": "test"
}

Result:

{
  "bindings": {
    "connection": "test"
  },
  "disabled": true
}

Problem with colon in key name

I have problem with magic-chunks in cake build. When I try to replace value of this configuration/appSettings/add[@key='ida:issuer']/@value, then I get error
("The ''' character, hexadecimal value 0x27, cannot be included in a name."), but this configuration/appSettings/add[@key='issuer']/@value works fine. It look colon makes difference in this case.

Possible to have recursive search in the config transform source path?

Would it be possible to add an option to perform a recursive search for the source path? I have not been able to get this to work. I have tried the standard formats such as "**\web.config", etc.
There is another task available in the marketplace which supports this option but I prefer your XML/Xpath searching since it requires no changes to the config files in the code repository.

VisualStudio Extension Update

Hi, I use magic chunks for our deploys and saw a post that you could delete nodes using the # symbol as of version 1.3.0 . The Visual Studio Extension is still running 1.2.0, when do you think you can push the latest version to the marketplace? I really like this tool and it helps make our agile process much more streamlined. src: #20

How to select processing instructions?

I have got a Wix Install file.

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?define ProductName="My product for ArcGIS 10.2"?>
  <?define ProductVersion="1.3.0.0" ?>
</Wix>

Where I would like to match the define with the ProductName and update the attribute value for that one. How should I select?
I tried with:

Wix/?define/@productname

and

Wix/processing-instruction(define)/@productname

But both fail in the update process.

Backslash transformed as double backslash

Hello,
In one of my projects, there's need to transform connection string in JSON config. The problem is, that in the connection string there's a backslash, ("Data Source=server\instanceName;Initial Catalog=... ") and it's transformed as double backslash ("Data Source=server\\instanceName;Initial Catalog=... "). Is there any way to solve/escape it?
Edit - it occured, that double backslash is OK

Release variables only work with "Inline JSON" transformation type

Hello,
It seems that release configuration variables in TFS 2015 only get their values replaced with "Inline JSON" transformation type. When using "JSON File", transformations do happen, but the values are not being replaced. The result web.config ends up having records like the one below.

<add key="Release" value="$(Release.ReleaseName)" />

Is that something can be fixed?

Thank you,
Anton

PS. Keep up the good work.

error CS1922 with CAKE on macOS

Hello.

With the current version 2.0.0.119 I get the error below when I run my CAKE build scripts on macOS. On Windows the same script works without errors.

$ ./build.sh --target=Tests
Downloading NuGet...
Feeds used:
  /Users/buildagent/.nuget/packages/
  https://api.nuget.org/v3/index.json

Restoring NuGet package Cake.0.23.0.
Adding package 'Cake.0.23.0' to folder '/Users/buildagent/buildAgents/gitlab/builds/6bacb613/0/XamarinApp/tools'
Added package 'Cake.0.23.0' to folder '/Users/buildagent/buildAgents/gitlab/builds/6bacb613/0/XamarinApp/tools'
Could not load /Users/buildagent/buildAgents/gitlab/builds/6bacb613/0/XamarinApp/tools/Addins/magicchunks.2.0.0.119/MagicChunks/lib/netstandard1.6/MagicChunks.dll (missing System.Runtime.Serialization.Formatters, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
Error: Error occurred when compiling build script: /Users/buildagent/buildAgents/gitlab/builds/6bacb613/0/XamarinApp/build.cake(114,40): error CS0012: The type 'Dictionary<,>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
/Users/buildagent/buildAgents/gitlab/builds/6bacb613/0/XamarinApp/build.cake(114,40): error CS1922: Cannot initialize type 'TransformationCollection' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
ERROR: Job failed: exit status 1

It seems, the .Net Standard version of librarary is missing some dependencies.

Version 1.2.0.58 (with CAKE_SETTINGS_SKIP_VERIFICATION=true) in CAKE 0.23 works as expected.

The ':' character, hexadecimal value 0x3A, cannot be included in a name

Hi, I'm using cake an trying to changes the Package.appmanifest file of Universal Windows Platform apps.

It works fine, until I'm trying to change an property that have namespaces (uap:VisualElements)
Package/Applications/Application/uap:VisualElements/@DisplayName

the error message is like:
The ':' character, hexadecimal value 0x3A, cannot be included in a name

Thank's and greetings!

XML web.config transform not working

When I try to alter a standard webconfig that looks like this:

<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <connectionStrings> <add name="DevOpsConn" connectionString="Data Source=mydatabase;Initial Catalog=DevOps;Persist Security Info=True;User ID=DevOpsUser;Password=foo" providerName="System.Data.SqlClient" /> </connectionStrings>

with this Transformation:

configuration/connectionStrings/add[@name='DevOpsConn']/@ConnectionString = "Data Source=mydatabase;Initial Catalog=DevOps;Persist Security Info=True;User ID=$(DevOpsROSQLUser);Password=$(DevOpsROSQLUserPswd)"

I get this release time error:
System.ArgumentException: Invalid JSON primitive: configuration

Yes...I've tried "auto detect" and "XML" as the file type. Both end the same way.
I've tried putting the entire statement in quotes, or each side of the statement in its own quotes.
Nothing will work.

Using magic-chunks with a netcoreapp1.0 project

Hello,

As I essentially want to transform appsettings.json during the MSBuild phase, I tried adding magic-chunks to my project but the following error message pops up:

Package MagicChunks 1.2.0.58 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package MagicChunks 1.2.0.58 supports: net45 (.NETFramework,Version=v4.5)

Any ideas? Any intent of support netcoreapps ?

Thanks,
DB

TFS Release Integration - Secret Variable Values?

Is there a way of handling the "secret" variable values when using the TFS Release task?
For instance, we have a number of passwords in our environment variables, which have been made secret to avoid exposing them to prying eyes.
capture
I would like the task to be able to decrypt these and put them in the transformed config files.
Thanks!

Nuget packages after 1.2.0 + fail to work with cake.build on VSTO

I'm not sure if this is really a bug in the Magic-Chunks nuget package building process or how cakebuild.net uses nuget references in it's codebase. I'm posting to help others.

Using magic chunks within a cake.build script via the Microsoft VSTO online CI plugin causes the nuget package to fail with cake.build CI tool. https://cakebuild.net/ when the process tries to use the magic chunks nuget packages greater than 1.2.0.x

This applies to cakebuild 0.21.1, 0.24.0 works as expected with Magic Chunks. Looks like I had checked a file into source control that fixed the edition of cakebuild.

Steps to reproduce

Add the following to a cake.build script
#addin nuget:https://www.nuget.org/api/v2?package=MagicChunks

Error: Failed to install addin 'MagicChunks'.

System.Exception: Unexpected exit code 1 returned from tool Cake.exe
PowerShell script completed with 1 errors.

Steps to resolve

Change the addin reference to
#addin nuget:https://www.nuget.org/api/v2?package=MagicChunks&version=1.2.0.58

Specify the correct node

Hi,

In the Xml I want to modify there are several nodes with the same name and I want to change a child node of one of the nodes.
Example

<info>
	<param>
		<option>AA</option>
	</param>
	<param>
		<option>BB</option>
		<argument>CC</argument>
	</param>
</info>

The value of the argument node should be modified depending on the type of build. But if I use "info/param/argument", it results in a new argument in the first param node.

Any way to fix this...Maybe with "info/param[2]/argument" to specify the correct node? Just like in XPath

Many thanks

Extension is not available in tasks list

TFS 2015 update 2 instance. Extension says it has been installed to the project collection (confirm screen says "Already Installed". Uninstall/reinstall does not work per previous closed issue...

Issues while using with a hosted linux agent

I get the below error while trying to use this task with the hosted linux agent -

A supported task execution handler was not found. This error usually means the task does not carry an implementation that is compatible with your current operating system. Contact the task author for more details.

When can this be addressed?

Enable VSTS task to run cross platform

The VSTS task.json only has an execution profile for Powershell which limits the running of this on Mac/Linux with the cross platform build agent.

It would be great to have a Node system also which uses typescript/javascript as Microsoft do with there powershell tasks when running on nix systems. e.g. the CopyPublishBuildArtifacts task.

Happy to help/contribute if desired to get this going.

Ampersands being escaped during XML transformation

I have the joy of working with some EDMX models that use connection strings that I am looking to transform. The connection string ends up looking something like:

<add name="Connection" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=server\instance;initial catalog=database;integrated security=True;multipleactiveresultsets=True;&quot;" providerName="System.Data.EntityClient" />

The thing of note is the &quot; in there which is unavoidable.

So in VSTS I've created a variable with the new connection string which looks something like:

metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=other-server\instance;initial catalog=database;integrated security=True;multipleactiveresultsets=True;&quot;

When transformed into the web.config it gets converted to:

metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=other-server\instance;initial catalog=database;integrated security=True;multipleactiveresultsets=True;&amp;quot;

WebDeploy provider

Investigate ability of integration config transformations into webdeploy pipeline.

Inline JSON: how to pick up two attributes with same name?

I am trying to use Inline JSON to modify web.config file. In this file, I have two host under hosts:
hosts
host hostname="http://localhost:2469"
host hostname="http://localhost:6299/"
I am not able to pick up those two hostname to edit using xpath. Got following errors:
##[error]System.Management.Automation.MethodInvocationException: Exception calling "Transform" with "4" argument(s): "The '[' character, hexadecimal value 0x5B, cannot be included in a name." ---> System.Xml.XmlException: The '[' character, hexadecimal value 0x5B, cannot be included in a name.

Is there anyway to address these two attributes or is this a bug? Need help on this.

Thanks!

Replacing with string that contains quotation

Suppose that I want to replace a string with a json object.

original file:
<key>old_value</key>

using this json:
"key" : "$(my_value)"

where my_value is a env variable. Suppose that my_value is a string that contains quotation mark, something like
my_value = string"string"maybeJson

When doing the replacement, the json replacement is no longer valid json. I tried escaping the value of my_value but that didn't work because TFS adds double escape. Any idea how to do this?

Attribute name with colon can't be transform in XML file type

When do transform with applicationsettings with the attribute key that contain colon, it will error.

Version: 1.2.0

Sample config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="blog:theme" value="green" />
  </appSettings>
</configuration>

Sample transform config

{
  "configuration/appSettings/add[@key='blog:theme']/@value": "red",
}

Error :

2017-11-14T11:04:04.9849036Z ##[error]System.Management.Automation.MethodInvocationException: Exception calling "Transform" with "4" argument(s): "The ''' character, hexadecimal value 0x27, cannot be included in a name." ---> System.Xml.XmlException: The ''' character, hexadecimal value 0x27, cannot be included in a name.
2017-11-14T11:04:04.9849036Z    at System.Xml.XmlConvert.VerifyNCName(String name, ExceptionType exceptionType)
2017-11-14T11:04:04.9849036Z    at System.Xml.Linq.XName..ctor(XNamespace ns, String localName)
2017-11-14T11:04:04.9849036Z    at System.Xml.Linq.XNamespace.GetName(String localName, Int32 index, Int32 count)
2017-11-14T11:04:04.9982685Z    at MagicChunks.Helpers.XmlExtensions.GetNameWithNamespace(String name, XElement element, String defaultNamespace)
2017-11-14T11:04:04.9982685Z    at MagicChunks.Helpers.XmlExtensions.<>c__DisplayClass1_0.<GetChildElementByName>b__0(XElement e)
2017-11-14T11:04:04.9982685Z    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
2017-11-14T11:04:04.9982685Z    at MagicChunks.Documents.XmlDocument.FindPath(IEnumerable`1 path, XElement current, String documentNamespace)
2017-11-14T11:04:04.9982685Z    at MagicChunks.Documents.XmlDocument.ReplaceKey(String[] path, String value)
2017-11-14T11:04:04.9982685Z    at MagicChunks.Core.Transformer.Transform(IDocument source, TransformationCollection transformations)
2017-11-14T11:04:04.9982685Z    at MagicChunks.TransformTask.Transform(String type, String sourcePath, String targetPath, TransformationCollection transformation)
2017-11-14T11:04:04.9982685Z    at CallSite.Target(Closure , CallSite , Type , Object , Object , Object , Object )
2017-11-14T11:04:04.9982685Z    --- End of inner exception stack trace ---
2017-11-14T11:04:04.9982685Z    at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
2017-11-14T11:04:04.9982685Z    at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
2017-11-14T11:04:04.9982685Z    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2017-11-14T11:04:04.9982685Z    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Passing a URL as the key (JSON)

Hi, in my replacement I need to pass a URL and a GUID, I am currently bound to the below spec of JSON, I cannot change the 'endpoints' to an array unfortunately, it has to remain an object, unfortunately aswell I need to pass the fully qualified domain, which forces me to pass in the "//" after the protocol.

i'm trying to add an endpoint to this key value pair object e.g.

{
    "authentication/aad/endpoints/https://anothertest.azurewebsites.net": "value"
}

to achieve this:

{
...
 "authentication": {
        "aad": {
            ...
            "endpoints": {
                "https://test.azurewebsites.net": "******-****-****-****-*********"
            }
            ...
        }
    }
...
}

Although i'm running into some problems when I it tries to parse the '//', is there a way to escape these characters, I've tried the normal escaping via '/', but that seems to produce:

{
"authentication": {
    "aad": {
       ...
      "endpoints": {
        "https:\\": {
          "\\": {
            "test.azurewebsites.net": "******-****-****-****-*********"
          }
        }
      }
      ...
    }
  }

is what I am trying to do supported? any thoughts on what I could do?

Access to the path '<source_file_to_transform>' is denied

Hi!

First of all, thank you for making this open source! I'm using it within TFS 2015 (update 4). Just after "get sources" I've tried to transform my web.config and got this:

##[error]Exception calling "Transform" with "4" argument(s): "Access to the path '<Path_to_my_build_agent_workspce><myproject>\web.config' is denied."

I thought it was an "IsReadOnly" issue, so I cleared it before using PowerShell and still with this error. Any ideas what should be the problem? Thank you in advance!

Could not load dll (missing assembly)

I'm stuck. Don't know how to get rid of this error:

Could not load C:\test\tools\Addins\MagicChunks.2.0.0.119\lib\netstandard1.6\MagicChunks.Cake.dll (missing System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
Could not load C:\test\tools\Addins\MagicChunks.2.0.0.119\lib\netstandard1.6\MagicChunks.dll (missing System.Runtime.Serialization.Formatters, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)

C:/test/build.cake(9,72): error CS0246: The type or namespace name 'TransformationCollection' could not be found (are you missing a using directive or an assembly reference?)
C:/test/build.cake(17,9): error CS0103: The name 'TransformConfig' does not exist in the current context

This is output from example script

Incompatible with Cake version > v.0.21.1

Using the latest version of Cake released today (v.0.22.0) and referencing MagicChunks in a cake script outputs this error:

Error: The assembly 'MagicChunks.Cake, Version=1.2.0.58, Culture=neutral, PublicKeyToken=null' is referencing an older version of Cake.Core (0.16.2). This assembly need to reference at least Cake.Core version 0.22.0. Another option is to downgrade Cake to an earlier version. It's not recommended, but you can explicitly opt-out of assembly verification by configuring the Skip Verification setting to true (i.e. command line parameter "--settings_skipverification=true", envrionment variable "CAKE_SETTINGS_SKIPVERIFICATION=true", read more about configuration at https://cakebuild.net/docs/fundamentals/configuration)

Unable to update xml tag attributes with a namespace.

My target xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myapp.name.here" android:installLocation="auto" android:versionCode="10000" android:versionName="1">
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application android:label="Scan Plan 2 Test" android:icon="@drawable/scanplanicon" android:theme="@style/MyTheme">
</manifest>

my Transform code:

{
"manifest/@android:versionCode" : "10001"
}

Issue:
the colon between 'android' and 'versionCode' is the incorrect syntax, and I cannot infer the correct way, nor can I find documentation that updating attributes with namespaces is even supported. Please help.

Release to nuget

#27 has been closed but the update has not yet been released to nuget.
Is anything blocking this? Had to pin quite a few packages to older versions to support this.

Thanks

Issue w/ Extension Showing up in on premise add tasks

Installed the extension fine this morning. Enabled on one of my collections. Says successful. I got into a build and or create new build, go to utility and am not seeing it showing. What are some potential reasons why? and where can i look for any 'error' messages or something
that could be hindering it from showing. Attached a screenshot .

image

Thanks!

Exception: There is empty items in the path

When transforming an XML from the sources, the task breaks with the following:

System.Management.Automation.MethodInvocationException: Exception calling "Transform" with "4" argument(s): "There is empty items in the path.
Parameter name: path" ---> System.ArgumentException: There is empty items in the path.
Parameter name: path
at MagicChunks.Documents.XmlDocument.ReplaceKey(String[] path, String value)
at MagicChunks.Core.Transformer.Transform(IDocument source, TransformationCollection transformations)
at MagicChunks.TransformTask.Transform(String type, String sourcePath, String targetPath, TransformationCollection transformation)
at CallSite.Target(Closure , CallSite , Type , Object , Object , Object , Object )
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Issue trying to run XML transformation

Running an xml transformation on an Appsettings key. Is there a problem including the ' character? I'm using the snippet i found on the github xml section. Getting the following issue below:

Transformation found: configuration/appsettings/add[@key='ida:KeyName']/@value: https://websitedomain.onmicrosoft.com/siteName
Transformation found: configuration/appsettings/add[@key='KeyName2']/@value: http://siteName.azurewebsites.net/
Transforming file E:\Work\24\s\AppName\App.config
System.Management.Automation.MethodInvocationException: Exception calling "Transform" with "4" argument(s): "The ''' character, hexadecimal value 0x27, cannot be included in a name." ---> System.Xml.XmlException: The ''' character, hexadecimal value 0x27, cannot be included in a name.

MagicChunks does not work when Cake.Json is also being used

When you have both Cake.Json and MagicChunks as addins, it throws this exception

Error: Roslyn.Compilers.CompilationErrorException: (2344,29): error CS0433: The type 'Newtonsoft.Json.Linq.JObject' exists in both 'MagicChunks, Version=1.1.0.34, Culture=neutral, PublicKeyToken=null' and 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' at Roslyn.Scripting.CommonScriptEngine.CompilationError(DiagnosticBag localDiagnostics, DiagnosticBag diagnostics) at Roslyn.Scripting.CommonScriptEngine.Compile(String code, String path, DiagnosticBag diagnostics, Session session, Type delegateType, Type returnType, CancellationToken cancellationToken, Boolean isInteractive, Boolean isExecute, CommonCompilation& compilation, Delegate& factory) at Roslyn.Scripting.CommonScriptEngine.Execute[T](String code, String path, DiagnosticBag diagnostics, Session session, Boolean isInteractive) at Roslyn.Scripting.Session.Execute(String code) at Cake.Scripting.Roslyn.Stable.DefaultRoslynScriptSession.Execute(Script script) at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary'2 arguments) at Cake.Commands.BuildCommand.Execute(CakeOptions options) at Cake.CakeApplication.Run(CakeOptions options) at Cake.Program.Main()

To reproduce, just take the demo repository from cake "getting started" guide. In the cake file, add "Cake.Json" and "MagicChunks" as #addin and run the default script. Compilation will fail.

What is the syntax for adding an element?

I have an xml config that contains several connection strings

 <connectionStrings>
    <add name="DatabaseConnectionSQL1" connectionString="use-dev-db1" providerName="System.Data.SqlClient" />
    <add name="DatabaseConnectionSQL2" connectionString="use-dev-db2" providerName="System.Data.SqlClient" />
  </connectionStrings>

During build I need to add a third connection string so that end up with

 <connectionStrings>
    <add name="DatabaseConnectionSQL1" connectionString="use-qa-db1" providerName="System.Data.SqlClient" />
    <add name="DatabaseConnectionSQL2" connectionString="use-qa-db2" providerName="System.Data.SqlClient" />
    <add name="DatabaseConnectionSQL3" connectionString="use-qa-db3" providerName="System.Data.SqlClient" />
</connectionStrings>

What would be the syntax for that?

Cannot see 'Config transformation' task when using TFS 2015 Update 2

Does the extension support TFS 2015 Update 2?

I do not see the extension listed under the "Add tasks" dialog when attempting to adding a build step. I have confirmed that the extension is installed on the server and is installed into the team project collection I'm trying to use it in.

Support of arrays in json configuration

I have a part of serilog config in json
"WriteTo": [ { "Name": "LiterateConsole" }, { "Name": "File", "Args": { "path": "C:\\Temp\\Logs\\log.txt", "rollingInterval": "Day" } } ],
Using the transform like this
{ "Serilog/WriteTo[1]/Args/path", "test" }

I got new node
"WriteTo[1]": { "Args": { "path": "test" } }

Is it possible to work with arrays in json config?

TransformationCollection load from file

Make possibility to load trans collection from file.
Like:
Web.config.mc =>

// https://github.com/sergeyzwezdin/magic-chunks
"configuration/appSettings/add[@key='ApiAuthKey']/@value" = "#{ApiAuthKey}"
"configuration/appSettings/add[@key='ApiBaseAddress']/@value" = "#{ApiAddress}"
"configuration/connectionStrings/add[@name='default']/@connectionString" = "Data Source=#{Database.Host};Initial Catalog=#{Database.Name};Integrated Security=True"
"configuration/system.web/machineKey/@decryptionKey" = "#{MachineKey.DecryptionKey}"
"configuration/system.web/machineKey/@validationKey" = "#{MachineKey.ValidationKey}"

Preserve XML header

If I have an existing XML document like this, and running some transformations the XML header in the first line will be removed.

<?xml version="1.0" encoding="utf-8"?>
<foo>
</foo>

Is there a way to have the XML header preserved?

Question about XML rootpath

Hi,
So I don't have much experience with this tool but maybe you could help me?

I think it has something todo with this part of the wiki but I do not quite get what you mean.

"Please note that you can have single root node for XML. So if the first element in transformation path does not match name of root element in source file you will get error: "

What I have is a file called POM.XML (see Below for refference) and I want to replace "inputSpec" in a vsts build task. This looks like this:
image

So when I run it I get this exception:
Exception calling "Transform" with "4" argument(s): "Root element name does not match path.

What am I doing wrong?

<project xmlns=some configuration stuff>

    <build>
        <plugins>
            <plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.2.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec></inputSpec>
                            <language>csharp</language>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Could not load file or assembly 'System.IO.FileSystem'

Hey Sergey,

looks like the new version doesn't work well.

  • Agent is running on Windows Server 2016
  • The Task was running well before today's update

Please let me know if you need more info.

2017-12-16T17:27:56.0021636Z ==============================================================================
2017-12-16T17:27:56.0021853Z Task : Config transformation
2017-12-16T17:27:56.0022091Z Description : Transform config file with Magic Chunks
2017-12-16T17:27:56.0022254Z Version : 1.3.1
2017-12-16T17:27:56.0022437Z Author : Sergey Zwezdin
2017-12-16T17:27:56.0022609Z Help : More Information
2017-12-16T17:27:56.0022797Z ==============================================================================
2017-12-16T17:27:56.4835847Z Preparing task execution handler.
2017-12-16T17:27:57.1161849Z Executing the powershell script: C:\VSTSAgents\Agent01_work_tasks\MagicChunks_985284e0-a7d2-4e4d-802c-0a516bffaadf\1.3.1\transform.ps1
2017-12-16T17:27:57.1260313Z "version": "1.0.830"
2017-12-16T17:27:57.1260539Z })
2017-12-16T17:27:57.1313342Z ##[error]System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
2017-12-16T17:27:57.8024964Z at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
2017-12-16T17:27:57.8113769Z at System.Reflection.Assembly.GetTypes()
2017-12-16T17:27:57.8114233Z at Microsoft.PowerShell.Commands.AddTypeCommand.LoadAssemblyFromPathOrName(List1 generatedTypes) 2017-12-16T17:27:57.8114760Z at Microsoft.PowerShell.Commands.AddTypeCommand.EndProcessing() 2017-12-16T17:27:57.8115031Z at System.Management.Automation.CommandProcessorBase.Complete() 2017-12-16T17:27:57.8115269Z Transformation found: version: 1.0.830 2017-12-16T17:27:57.8115437Z 2017-12-16T17:27:57.8115577Z 2017-12-16T17:27:57.8115796Z Transforming file C:\VSTSAgents\Agent01\_work\1\s\vss-extension.json 2017-12-16T17:27:57.8115985Z 2017-12-16T17:27:57.8116120Z 2017-12-16T17:27:57.8117825Z ##[error]System.Management.Automation.MethodInvocationException: Exception calling "Transform" with "4" argument(s): "Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified." ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 2017-12-16T17:27:57.8118521Z at MagicChunks.TransformTask.Transform(String type, String sourcePath, String targetPath, TransformationCollection transformation) 2017-12-16T17:27:57.8118881Z at CallSite.Target(Closure , CallSite , Type , Object , Object , Object , Object ) 2017-12-16T17:27:57.8119172Z --- End of inner exception stack trace --- 2017-12-16T17:27:57.8119478Z at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) 2017-12-16T17:27:57.8121074Z at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame)
2017-12-16T17:27:57.8121468Z at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2017-12-16T17:27:57.8121808Z at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2017-12-16T17:27:57.8126586Z ##[error]PowerShell script completed with 2 errors.

Update Cake addin to Cake 0.26.0

Cake 0.26.0 introduced breaking changes in the API. The Cake addin should be built against Cake 0.26.0 to be compatible with current version

Allow build variables for transformations

I need to transform a connection string based on the build variable Build.SourceBranch.
It would be nice if your tool supported passing in build variables in VSTS, so it is possible to create transformations based on these variables.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.