2017-09-07 58 views
0

我有一個NLog.config文件,我想在發佈我的網站之前進行轉換。類似於web.config的轉換方式。我該如何做到這一點?我無法找到如何做到這一點的可靠資源。NLog.config轉換

我嘗試添加變換到的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> 

還添加了NLOG到的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> 

但這並不變換NLog.config複製到包目錄(或部署到AWS時)。原始的NLog.config被複制,並且也存放在/ bin目錄中。

+1

查找到SlowCheetah - https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.SlowCheetah-XMLTransforms – JAZ

+0

你可以將這個配置你構建項目之後,但你會發布它們之前? –

+0

謝謝你,約翰,指出我在正確的方向。我模仿SlowCheetah完成的更改並手動編輯我的csproj。下面將添加解決方案 – Dan

回答

0

SlowCheetah似乎做我想要的。我已經嘗試過了,我已經修改了自己的csproj補充:

<TransformOnBuild>true</TransformOnBuild> 

<IsTransformFile>True</IsTransformFile> 

所以最終的變化是這樣的:

<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> 

這就是它和NLog.config被轉換!這個目標之下是沒有必要:

<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>