问题
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 defaultweb.config
will be generated in publish folderOverwriteReadOnlyFiles="true"
- without thisweb.config
cannnot be replaced
来源:https://stackoverflow.com/questions/44742822/replace-web-config-in-asp-net-core-vs-2017-on-publish