ApplicationInsights.Config 文件转换

问题描述 投票:0回答:1

我们有ApplicationInsights.Config,它与Web.Config 一样位于根目录。我想对其应用转换。我能够使用 SlowCheetah 包来完成基于发布/调试配置的工作,并将转换文件放入 bin 文件夹中。现在我们有 2 个 ApplicationInsights.Config - 一个位于根目录,另一个位于 bin 文件夹。根据下面的文章,它将始终从根目录中选择,那么我如何使用此包推送到根目录转换。

https://github.com/microsoft/ApplicationInsights-dotnet/blob/main/examples/.NET%20Config%20File/Readme.md

c# azure azure-application-insights transformation
1个回答
0
投票

根据下面的文章,它将始终从根目录中选择,

  • 是的,默认情况下,当构建应用程序时,根

    ApplicationInsights.config
    的更改将反映到bin
    ApplicationInsights.config
    文件中。

  • 要将转换更改为根配置目录,您可以在预构建事件命令行中设置命令。

  • 右键单击

    Application folder
    =>
    Properties
    =>
    Build Events

  • 在命令行中添加以下命令。

copy $(TargetDir)ApplicationInsights.Debug.Config $(ProjectDir)ApplicationInsights.Config
  • 这可以添加到
    .csproj
    中。

enter image description here

  • 当我们在本地运行应用程序时,我们选择“调试”选项。

enter image description here

  • 因此,我设置命令将调试文件更改复制到根目录配置文件。

  • ApplicationInsights.Debug.config
    中进行所需的更改并构建应用程序。

  • 更改目标配置文件的属性(这里我使用的是调试)。

enter image description here

Build Action - Content
Copy to Output Directory - Copy always/Copy if newer
  • 立即构建/运行应用程序。

  • 可以看到Debug文件的配置被复制到根配置文件中。 (它也将被复制到 bin 文件夹,但我们需要根配置文件。应用程序将如何选择根文件)。

enter image description here

根据您的要求更改命令行目标(调试/发布)。

请参阅 devcodef1 博客了解更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.