Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visual studio publish choosing wrong web.config transform

based on what i read, as long as you have a transform that matches the name of a publish profile, it should be applied, but this is not the case for me.

publish profiles

PublisProfiles
    dev.pubxml
    local.pubxml

transforms

 Web.Config
     Web.Debug.config
     Web.local.config
     Web.Release.config

when i publish using local config, i see this:

Transformed Web.config using  C:\...\Web.Release.config into obj\Release\TransformWebConfig\transformed\Web.config.

so it's using Release.config .. i opened up local.pubxml and tried changing this

<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>

to:

<LastUsedBuildConfiguration>local</LastUsedBuildConfiguration>

but then it's using Web.Debug.config transform.

dev, release, local transforms are identical aside from a few transformed properties ..

like image 838
Sonic Soul Avatar asked Mar 17 '14 22:03

Sonic Soul


People also ask

How do I create a new transformation in Web config?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).

Where is Web config file in Visual Studio 2022?

config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ folder.

What is Web config transform?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.


2 Answers

My problem with that had to do with the platform configuration:

At the Configuration Manager window, you can choose the config name ("Active solution configuration" combobox) and the target platform ("Active solution platform" combobox). I correctly made the setup of my new configuration ("MyStagingConfig", say) for each project, but forgot about the platform - so I configured it all in "Mixed platform".

When I published the project using "MyStagingConfig - Any CPU", it transformed the config with the Web.Staging.config file, instead of Web.MyStagingConfig.config. After a little headache, I realised that the "Any CPU" platform, which I hadn't configured, was configured by default to publish the project with the "Staging" config (as I had imported the settings from the "Staging" config when creating "MyStagingConfig").

like image 130
Raphael Avatar answered Oct 23 '22 06:10

Raphael


The publish pipeline should be using both your profile's transform and the build configuration transform.

The logic for this is that your profile transform probably has destination-specific settings (e.g. which connection strings to use in Production vs. Staging), but your build configuration has build-specific settings (e.g. Debug has debugging related settings but Release turns them off). Allowing you to mix and match these gives greater flexibility (need to publish to Staging with debug settings enabled? Just use the Debug build configuration with the Staging profile). Settings from web.YourProfile.config will always overrule any prior transforms.

like image 28
Jimmy Avatar answered Oct 23 '22 05:10

Jimmy