Code Monkey home page Code Monkey logo

configurationtransform's Introduction

[ARCHIVED] ConfigurationTransform

Build Status GitHub release

As part of the archival process, I'm closing all open issues and pull requests.


Microsoft has a neat out of the box solution for Web Application Projects configuration transform which gives you the ability to have multiple configurations for each build environment (i.e. web.config). Somehow this ability is not included in other project types.

When you have multiple projects with many configurations the dev->staging->production task becomes very unpleasant. I remember back then having one app.config file with different commented configurations for each environment struggling to comment uncomment the right ones. Well I'm happy those days are over. After using app.config transformations for two years doing it the hard way by editing the project file and adding the configuration files manually, I thought it would be nice to write extension to automate this task.

There are many articles and solutions out there, some of them used as the inspiration for this extension.

When I developed this extension I had a few things in mind:

  • Multiple configuration files for different environments (e.g. dev/staging/production).
  • ClickOnce support.
  • Self-contained solution - no need to install the extension on all dev/ build server machines.
  • Simple few clicks and you are set.

For more information how to use XDT (XML document transform) see http://go.microsoft.com/fwlink/?LinkId=125889

GitHub Sample ConfigurationTransformSample

Step by Step Instructions:

  1. Add App.config file to project

  2. Right click App.config file in solution explorer and select Add Config Transforms

    Notice that you have new App.$$$.config files under App.config

    corresponding to build configurations

  3. Set the source App.config

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appSettings>
    <add key="Environment" value=""/>
    </appSettings>
    </configuration>
  4. Set the target App.Debug.config

    <?xml version="1.0"?>
    <!-- For more information on using app.config transformation visit    http://go.microsoft.com/fwlink/?LinkId=125889 -->
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
     <appSettings>
      <add key="Environment" value="Debug" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
     </appSettings>
    </configuration>
  5. Build project.

Linked Configs Step by Step Instructions:

  1. Add link(Existing Item...) App.config file to project

  2. Right click link App.config file in solution explorer and select Add Config Transforms

    Click Yes button, if you select No button concrete(not linked) config files will be created which suits certain use case

    Notice that you have new App.$$$.config files under App.config

    corresponding to source App.config files

  3. Continue with step 3 above...

Preview:

Changelog:

From v3.2 and above Release Notes

  • 3.1 - Aug 19, 2017

    • Add support for Visual Studio 2017.
  • 3.0 - Feb 27, 2016

    • Add support for any config file (*.config) not just app.config
    • Update demo solution.
  • 2.2 - Feb 09, 2016

    • Add support for Visual Studio 2015.
  • 2.1 - Sep 29, 2014

    • Hot fix for v2.0. Remove 'Microsoft.VisualStudio.Shell.12.0 dependency.
  • 2.0 - Sep 28, 2014

    • Add preview support.
  • 1.6 - May 28, 2014

    • Fix minor bug.
  • 1.5 - May 24, 2014

    • Fix linked configs relative path.
    • Add support for source linked configs not included in project.
  • 1.4 - Apr 13, 2014

    • Fix linked configs creation when source config is located in solution sub folder.
  • 1.3 - Oct 05, 2013

    • Add support for Visual Studio 2013.
    • Add support for linked configs transformations.
    • Add deployment(Click-Once) support for class library projects.
  • 1.2 - May 03, 2013

    • Fix Visual Studio 2012 compatibility issue.
  • 1.1 - Nov 24, 2012

    • Add support for Visual Studio 2012.
    • Fix typo in xml element.
  • 1.0 - May 27, 2012

    • First release.

configurationtransform's People

Contributors

azure-pipelines[bot] avatar golavr avatar markusobviuse 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

configurationtransform's Issues

AppConfigWithTargetPath with duplicated value

The AfterCompile target created contains AppConfigWithTargetPath changes which remove App.config and add transformed .config.

This seems to sometimes malfunction on VS 2017 (15.6.1) as AppConfigWithTargetPath is reused - the transformed .config is added twice, and target "GenerateApplicationManifest" fails on "ConfigFile" (Microsoft.Common.CurrentVersion.targets(3812,9): error MSB4094).

This may be corrected for example by not adding twice the same .config
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config" KeepDuplicates="false">

VS 2019 community 16.4.0, Error in Preview Config Transforms

  1. Right Click on App.Config
  2. Click on Preview Config Transforms

Show Error Message "Cannot find source config".

In short ... probably Golavr know how ..

Related to class ProjectItemExtensions
Method
public static ProjectItem ParentProjectItemOrDefault(this ProjectItem source)
{
/*
* Ack Start
*/
Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
ProjectItem pp = source?.Collection?.Parent as ProjectItem;
if (pp != null) return pp;

        pp = source as ProjectItem;
        return pp;
        /*
         * Ack End
         */
        /* Original
        // Something was changed in OLE? Microsoooftttt?
        if (!(source?.Collection?.Parent is ProjectItem parent))
        {
            ProjectItem p = source as ProjectItem;
            return null;
        }
        return parent;
        */
    }

Publish failed with visual studio 2019

windows 10 & visual studio 2019 16.0.3

  1. install success
  2. fist time Add Config Transforms failed, but try again success
  3. CANNOT choose direct config to publish the project
  4. FAILED when publish, error message: "obj\sat\xxx.config;obj\sat\xxx.config" is an invalid value for the "ConfigFile" parameter of the "GenerateApplicationManifest" task. Multiple items cannot be passed into a parameter of type "Microsoft.Build.Framework.ITaskItem"

Multiple Configuration Transforms Not Working

There is a bug with the current implementation that was identified by Dan Bullock on 9/19/2017 wherein the extensions is created a new AfterBuild section in the project file for each config transform in a project, which causes only the first transform to be applied in a scenario where a project has more than one config file that needs to be transformed. Dan also presents the solution there. Please fix it if you have time.

"The sample project is not correct. The sample defines multiple <AfterBuild> but when it actually can only be defined once. Each definition replaces the previous.

In .csproj it should be a single AfterBuild with each TransformXml having a condition:

<Target Name="AfterBuild">
<!--Generate transformed config in the output directory-->
<TransformXml Condition="Exists('data.$(Configuration).config')" Source="data.config" Destination="$(OutputPath)data.config" Transform="data.$(Configuration).config" />
<TransformXml Condition="Exists('plainxml.$(Configuration).config')" Source="plainxml.config" Destination="$(OutputPath)plainxml.config" Transform="plainxml.$(Configuration).config" />
</Target>
By Dan Bullock 9/19/2017"

DependentUpon makes app.env.config files invisible in VB project

Apparently, the nesting feature of files has been removed from VB projects. When you add a <DependentUpon/> element, the file is not shown in Visual Studio (2015 Community in my case).

See the following for more info: https://developercommunity.visualstudio.com/content/problem/165081/vb-project-not-showing-dependentupon-files-anymore.html

I tried "Show All Files" as the post suggests, but that also does not show the app.env.config files in Visual Studio. So, I would suggest removing the <DependentUpon> elements when the project is VB, as this "feature" doesn't seem to work at all in that environment.

The transforms seem to go smoothly, though. Nice work!

Corrupts VS2019 .NET Core project

Tried to use it on a .NET Core Console app project (C#) and after adding transforms, project cannot be loaded. Getting error:

error : The attribute "xmlns" in element <UsingTask> is unrecognized.

Had to remove the transformation sections from the project file to make it work.

Worked fine on a non-Core project.

Can't preview with path containing dot

I'm getting the following error in the output console when I try to preview a transformation in our project:

Failed to open C:\Projects\Projects.Web\
Could not find a part of the path 'C:\Projects\Projects.Web\'.

The issue happens when there is a dot in the path. Without the dot in the path, it works again.

Only show "Add Transform" and "Show Transform" where if makes sense

Would be good to include some logic to ConfigurationTransformPackage.cs -> BeforeQueryStatus()-methods to only show each options when it makes sense.

What I'm thinking:

Add Configuration Transforms
Should only be visible (or maybe enabled) when the selected file is a .config-file that has no children.

Preview Configuration Transforms
Should only be visible (or maybe enabled) when the selected file has a parent file that is a .config-file. This means that the selected file is an actual transform.

Make it compatible with VS 2017 new .csproj format

When used in a VS2017 .csproj (i.e. ), targets must be changed to follow the new syntax, and therefore be correctly executed.

before (will not be executed)
<Target Name="AfterCompile" ... >
<Target Name="AfterPublish" ... >

after (will be executed)
<Target Name="TransformConfig" AfterTargets="AfterCompile" ... >
<Target Name="CopyTransformedConfig" AfterTargets="AfterPublish" ... >

The new Target names above are just an exemple, it does not matter anymore AFAIK.

Line breaks not maintained

Line breaks between attributes (+elements) are removed. This causes the preview to not show the changes in a meaningful manner.

If the given config is:

<Setting1
    value1="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    value2="b"
    value3="3"
/>

And the transform is:

<Setting1 xdt:Transform="SetAttributes(value2)"
    value2="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
/>

The result is:
<Setting1 value1="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" value2="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" value3="3"/>

Depending of the number of attributes or the length of the values, the line does not fit on the visible part of the screen what makes it difficult to see the changes.

I would like to have it like:

<Setting1
    value1="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    value2="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
    value3="3"
/>

what causes the preview to mark only the lines (value1, value2) as modified.

Failure to Build VS 2017

I had experienced the same issue as seen in #25
I wanted to readdress the issue and highlight the work around. As mentioned in one of the comments from https://www.oipapio.com/question-3728301 in my case the issue was resolved by replacing
<AppConfigWithTargetPath Remove="app.config" />
with
<AppConfigWithTargetPath Remove="@(AppConfigWithTargetPath)" />
inside the .csproj resolved the issue.
I've confirmed that the transformation is still working after this change. Any particular reason this solution isn't there by default?

Error in building after extension installation

I just installed the configuration transform extension and get an error on my initial clean/build:

"obj\Debug\FTP.exe.config;obj\Debug\FTP.exe.config" is an invalid value for the "ConfigFile" parameter of the "GenerateApplicationManifest" task. Multiple items cannot be passed into a parameter of type "Microsoft.Build.Framework.ITaskItem".

Can you suggest how I can resolve it?

VS2017 not create link

Hello,

I follow your guide, but when I try click on app.config for copy link to app.debug.config, I have message "not change were made" ??
Thanks

M.

Issue with vb.net web site

I have a new install of VS2015 Enterprise and have a website added to my project. The Configuration Transform extension is installed.

When I right click on a web.config file, I don't see any option 'Add config Transform'.

I saw a comment on StackOverflow that vb.net is not supported. Is this so?

Transform task blocking AutoGenerateBindingRedirects

I finally figured out what one of my projects was not getting automatic binding redirects written during compilation. As soon as I stripped out the configuration that the Configuration Transform extension added to my csproj, assembly redirects were getting added again.

Any chance to get this to work with automatic assembly redirects?

Add config transform throws Object reference error

Microsoft Visual Studio Enterprise 2019
Version 16.5.4
When I click Add config transform on .net framework 4.7.2 project, I get a visual studio error - Object reference not set to an instance of an object.

Make it compatible with VS 2017 new .csproj format

Creating new issue for the following Closed issue as I don't have permission to reopen and I don't believe issue was resolved.

Issue Url

I've uploaded sample project demonstrating error to original issue.

This is very confusing as the sample project I've uploaded is simply the default"out-of-the-box"
VS 2017 project template and ConfigurationTransform does not work.

Xml Node inserted twice on tripple solution configuration

I've configured a third solution configuration for a test installation of my software. So I also added a third config transformation file to set the specific config values for my test installation. The problem is that the extension seems to execute an insert transformation twice. Here is how I've configured my project:

Those are the names of my config transform files:
app.Debug.config
app.Release.config
app.Test.config

The app.Release.config and app.Test.config both contain this transformation:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="MyBinding" xdt:Locator="Match(name)">
          <httpTransport xdt:Transform="Remove" />
          <httpsTransport xdt:Transform="Insert" />
        </binding>
      </customBinding>
    </bindings>
  </system.serviceModel>
</configuration>

As a result I'm getting the httpsTransport element twice when compiling in "Release" or "Test" solution configuration. As a workarround I've now simply added bevor adding the httpsTransport again.

Is there a better solution to this problem or is this maybe a bug in the extension?

error : The attribute "xmlns" in element <UsingTask> is unrecognized.

After "Add Config Transform" the project unloaded and throws this error (VS2019):
C:*<solutionFolder><projectName>.csproj : error : The attribute "xmlns" in element is unrecognized. C:*<solutionFolder><projectName>.csproj

the following lines is added to the project (which the xmlns that causing the problem):
(at the top) :

(in the at the end):



any idea why?

Configuration changes not output if app.XXX.config is not present

I just spent quite a bit of time trying to work out why a new configuration setting wasn't being read when debugging for a ClickOnce project.

It turns out that it was all due to the fact that I never created an app.Debug.config file when upgrading the project, thus the entire config transform process was skipped.

  <Target Name="app_config_AfterCompile" AfterTargets="AfterCompile" Condition="Exists('app.$(Configuration).config')">
	<!--Generate transformed app config in the intermediate directory-->
	<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
	<!--Force build process to use the transformed configuration file from now on.-->
	<ItemGroup>
	  <AppConfigWithTargetPath Remove="@(AppConfigWithTargetPath)" />
	  <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
		<TargetPath>$(TargetFileName).config</TargetPath>
	  </AppConfigWithTargetPath>
	</ItemGroup>
  </Target>

Essentially the Condition="Exists('app.$(Configuration).config')" is skipping the whole transform process. I suppose it was logical to assume that if you skipped it, the default MSBuild behavior of copying the App.config file over to MyApp.exe.config would take place, but that is not what is happening. Although MyApp.exe.config does get generated, it is apparently not being done based on the latest version of App.config.

Just to be clear, I don't need to do any transformation during debugging. But without an app.Debug.config file, debugging is working but the build does not pass through the latest changes to the config settings. Adding the config file solves the issue, but it would definitely be best if the MSBuild configuration didn't require one in order to output the right .config settings.

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.