Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET web.config transformation related on publish profile name

I have three publish profile on my ASP.NET MVC project.

enter image description here

I need to add transformations for all of them. For doing that, I picked "Add Config Transform" on web.config file and got 4 web configs:

enter image description here

But I can't understand how can I assign any of them to any publish profile. For example, I can't find the right config file for put transformation for development publish profile. How can I do that ? Thanks for any advice.

like image 994
kkost Avatar asked Feb 14 '17 23:02

kkost


2 Answers

I've created a new web config which I named "Web.development.config". That's my project file code for transformations:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="AfterCompile" Condition="exists('Web.$(Configuration).config')">
    <!-- Generate transformed app config in the intermediate directory -->
    <TransformXml Source="Web.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="Web.$(Configuration).config" />
    <!-- Force build process to use the transformed configuration file from now on. -->
    <ItemGroup>
      <AppConfigWithTargetPath Remove="Web.config" />
      <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
        <TargetPath>$(TargetFileName).config</TargetPath>
      </AppConfigWithTargetPath>
    </ItemGroup>
  </Target>

So with this solution you can use Web.<your publish profile name>.config

like image 166
kkost Avatar answered Sep 28 '22 05:09

kkost


When you want to create a publish profile, you see a dropdown list where you specify what mode it will be. Try to create a new publish profile and you will see.

enter image description here

like image 41
Amir H. Bagheri Avatar answered Sep 28 '22 06:09

Amir H. Bagheri