SlowCheetah does not convert web.config to assembly

I installed the SlowCheetah package via nuget and added conversion files for my web.config based on the Build config. However, when building web.config is not converted. I checked the project file and saw the entries for the SlowCheetah PropertyGroup and Import elements. I do not see the goal for the conversion in the project file. If I add app.config, the app.config file will be converted. I understand that installing the SlowCheetah package should automatically add the goal of converting web.config to the MSBuild file for the project. I can add it manually, but I thought SlowCheetah was doing this out of the box. I'm missing something. Please let me know. My requirement is that the web.config file must be converted based on the assembly configuration, and the converted web.config file must be located in the output directory. Thanks and appreciate all the help.

+6
source share
3 answers

Visual Studio only performs conversion when you deploy your project using the publish function. To do this, when you build, you need to configure your MSBuild script. The complete solution is here . Here's the main thing:

Files in the project Create a file named Web.Base.config, except for the existing Web.Debug.config and Web.Release.config. This file will be the equivalent of the old Web.config file, as it will become the basis for tranformation. You will get these files:

Web.config, Web.Base.config, Web.Debug.config, Web.Release.config, and Web.config. Add the following configuration to the bottom of the .csproj file, before closing the -tag:

<Target Name="BeforeBuild"> <TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config" /> </Target> 

UPDATE: from a reminder in the comments, I realized that I also have a problem with Visual Studio that double-converts XML when publishing a project. The solution to this is to add a condition to the Target-tag:

 <Target Name="BeforeBuild" Condition="'$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == ''"> 
+9
source

To clarify Philip's answer, I found a possible simpler solution: There is no need for Web.Base.Config and no problems rewriting your web.config, which causes problems in Source Control.

BeforeBuild: you assign the target name TargetDir en TargetFileName.

AfterBuild: You will copy this to your published websites after the build is complete.

 <Target Name="BeforeBuild"> <TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="$(TargetDir)$(TargetFileName).config" /> </Target> <Target Name="AfterBuild" Condition="'$(Configuration)' == 'Dev' Or '$(Configuration)' == 'Test' Or '$(Configuration)' == 'Prod'"> <Delete Files="$(TargetDir)_PublishedWebsites\$(ProjectName)\Web.config" /> <Copy SourceFiles="$(TargetDir)$(TargetFileName).config" DestinationFiles="$(TargetDir)_PublishedWebsites\$(ProjectName)\Web.config" /> </Target> 
+3
source

Have you set the copy to output directory property of your conversion files to Do Not Copy? Also check the project file.

The following entries should be added to the project file (depending on the installed version 2.5.7):

 <PropertyGroup Label="SlowCheetah"> <SlowCheetah_EnableImportFromNuGet Condition=" '$(SC_EnableImportFromNuGet)'=='' ">true</SlowCheetah_EnableImportFromNuGet> <SlowCheetah_NuGetImportPath Condition=" '$(SlowCheetah_NuGetImportPath)'=='' ">$([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\..\packages\SlowCheetah.2.5.7\tools\SlowCheetah.Transforms.targets ))</SlowCheetah_NuGetImportPath> <SlowCheetahTargets Condition=" '$(SlowCheetah_EnableImportFromNuGet)'=='true' and Exists('$(SlowCheetah_NuGetImportPath)') ">$(SlowCheetah_NuGetImportPath)</SlowCheetahTargets> 

 <Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)')" Label="SlowCheetah" /> 
0
source

Source: https://habr.com/ru/post/952855/


All Articles