replace web.config in asp.net core vs 2017 on publish

和自甴很熟 提交于 2019-12-14 04:17:54

问题


i'm trying to replace the web.config with the production version.

I have the production version in ~\production\web.config (tilda as the root of my project folder).

I found this in the migration document

<ItemGroup>

  <Content Include="Views\**\*" PackagePath="%(Identity)" />

  <None Include="notes.txt" CopyToOutputDirectory="Always" />
  <!-- CopyToOutputDirectory = { Always, PreserveNewest, Never } -->

  <None Include="publishnotes.txt" CopyToPublishDirectory="Always" />
  <!-- CopyToPublishDirectory = { Always, PreserveNewest, Never } -->
</ItemGroup>

I tried to use something like this

<ItemGroup>   
     <None Include="_production\web.config" CopyToPublishDirectory="Always" /> 
</ItemGroup>

but in this way the folder and the file both will copy to the publish directory. it's a combination of mapping and publish and unfortunately the documentation is suffering from lack of example, so i tried to guess/figure it out by combining the mapping example with the publish.

first i tried this:

<None Include="_production\web.config" CopyToPublishDirectory="Always"  PackagePath="in/web.test"/>

so i was expecting to see a in folder in the publish directory but didn't.

i tried

<None Include="_production\web.config" CopyToPublishDirectory="Always"  PublishPath="in/web.test"/>

but didn't worked as well.

you can find the migration document here


回答1:


Not sure if this is the most right way, but you may achieve this using Copy task directly:

<Target Name="CustomScript" AfterTargets="GeneratePublishRuntimeConfigurationFile">
    <Copy SourceFiles="_production\web.config" 
          DestinationFolder="$(PublishDir)" 
          OverwriteReadOnlyFiles="true"
          SkipUnchangedFiles="false" />
</Target>
  • AfterTargets="GeneratePublishRuntimeConfigurationFile" as we want to do replacement only after default web.config will be generated in publish folder
  • OverwriteReadOnlyFiles="true" - without this web.config cannnot be replaced


来源:https://stackoverflow.com/questions/44742822/replace-web-config-in-asp-net-core-vs-2017-on-publish

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!