Joseph
Joseph

Reputation: 2255

NLog.config Transformation

I have an NLog.config file that I want transformed before publishing my site. Similar to how web.config is transformed. How do I accomplish this? I couldn't find any solid resources on how to do this.

I tried adding a transform to the csproj

  <Target Name="BeforeBuild" Condition="exists('NLog.$(Configuration).config')">
    <Message Text="Tranforming NLog..."/>  
    <TransformXml Source="NLog.config" Transform="NLog.$(Configuration).config" Destination="$(OutputPath)\NLog.config" />
  </Target>

Also added the NLog to csproj:

   <Content Include="NLog.config">
      <SubType>Designer</SubType>
    </Content>
    <None Include="NLog.aws-prod.config">
      <DependentUpon>NLog.config</DependentUpon>
    </None>
    <None Include="NLog.aws-test.config">
      <DependentUpon>NLog.config</DependentUpon>
    </None>

but this doesn't copy the transformed NLog.config to the package directory (or when deploying to AWS). The original NLog.config is copied and a copy in the /bin directory as well.

Upvotes: 0

Views: 1531

Answers (1)

Joseph
Joseph

Reputation: 2255

SlowCheetah seems to do what I want. I've tried it and I've made changes to my csproj to add:

<TransformOnBuild>true</TransformOnBuild>

and

<IsTransformFile>True</IsTransformFile>

so the final change looks like this:

<Content Include="NLog.config">
  <TransformOnBuild>true</TransformOnBuild>
  <SubType>Designer</SubType>
</Content>
<None Include="NLog.aws-prod.config">
  <DependentUpon>NLog.config</DependentUpon>
  <IsTransformFile>True</IsTransformFile>
  <SubType>Designer</SubType>
</None>
<None Include="NLog.aws-test.config">
  <DependentUpon>NLog.config</DependentUpon>
  <IsTransformFile>True</IsTransformFile>
</None>

That's it and NLog.config is transformed!! This target below wasn't needed:

<Target Name="BeforeBuild" Condition="exists('NLog.$(Configuration).config')">
    <Message Text="Tranforming NLog..."/>  
    <TransformXml Source="NLog.config" Transform="NLog.$(Configuration).config" Destination="$(OutputPath)\NLog.config" />
  </Target>

Upvotes: 1

Related Questions