Question

I have two different ways to deploy my web app - one via IIS Web Deploy, hooked up via MSBuild arguments in a custom build template, and using the One-click publish built into Visual Studio. I have also installed the Slow Cheetah transforms, and can successfully transform Web.config files.

However, I'm stuck on the Nlog.config files. If I use One-click publish, the webapp deploys fine with the updated config file. However, using the actual build process, nothing gets transformed. The source Nlog.config file is copied to the drop locations, the deployment package, and the output folder on the remote server.

The .csproj file has Nlog set up the same way as web.config, i.e.

<Content Include="NLog.config">
  <TransformOnBuild>true</TransformOnBuild>
    <Content Include="Web.config">
  <SubType>Designer</SubType>
  <TransformOnBuild>true</TransformOnBuild>
<Content Include="NLog.Debug.config">
  <DependentUpon>NLog.config</DependentUpon>
  <IsTransformFile>True</IsTransformFile>

The SlowCheetah preview function lets me know that my transform files are well-formed, as well. Not sure what I could be missing.

Was it helpful?

Solution

Well, I really biffed that one. After much poking, I found that I needed to include the following -

 <Import Project="TransformsFiles.targets" />
   <PropertyGroup>
     <TransformOnBuild>true</TransformOnBuild>
   </PropertyGroup>

right above the final Project tag, as Sayed mentions here. This will actually transform the files, but they still won't deploy successfully. I'll have to add in some post-build events or something to take care of that. Not the best solution, but it's working, at least.

UPDATE: Just for comprehension, to deploy the files, I had to edit the .csproj file to include a new target and dump them manually to the remote server, but only after the transformation had completed. Take a look at your log file to see what's going on, then just pick up the transformed file and move it to the remote server. That part of the code looks like this -

<Target Name="PostTransformNLogConfig" AfterTargets="TransformAllFiles">
  <Copy Condition="Exists('d:\Builds\Binaries\NLog.config' )"
        SourceFiles="d:\Builds\NLog.config"
        DestinationFiles="\\remoteserver\NLog.config" />
</Target>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top