在发布时替换asp.net core中的web.config vs 2017 [英] replace web.config in asp.net core vs 2017 on publish

查看:296
本文介绍了在发布时替换asp.net core中的web.config vs 2017的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试用生产版本替换web.config。

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

我在〜\production\中具有生产版本\web.config (以tilda作为我的项目文件夹的根)。

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.

首先我尝试了此方法:

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

我尝试过

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

但效果不佳。

您可以找到迁移文档

推荐答案

不确定这是否是最正确的方法,但是您可以使用直接复制任务:

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 ,因为我们只希望在发布文件夹中生成默认 web.config 后进行替换

  • OverwriteReadOnlyFiles = true -没有此 web.config 不能被替换

    • 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
    • 这篇关于在发布时替换asp.net core中的web.config vs 2017的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆