我有一个NLog.config文件,我想在发布我的站点之前进行转换。类似于web.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目录中复制一个副本。
发布于 2017-09-08 13:16:54
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>https://stackoverflow.com/questions/46093550
复制相似问题