Pages

25/07/2026

ClickOnce maintain and deploy to DEV, UAT, PRO

 



事緣

一般來說program 不論 server / client 都分成DEV / UAT / PROD 三個 environment

.net Core 之前通常都放在 web.config / app.config

在更早之前很多都沒有固定位置,各自發揮

然後Git來了

假如用 branch 分開 不同的config,海豚不太喜歡

即是只有app.config

branch-DEV, branch-UAT, branch-PROD 的value都不同

日後 dev 加減改value,很容易出現 conflit

然後海豚最近接手一套project的source code

問題一

然後build and debug UAT 時一直報錯

因為 AssemblyName 在UAT時改了名稱


問題二


然後build and debug DEV 時一直報
config 有attribute duplicated





Soluation 解決方案

海豚最後明白了為什麼上手要

特別為UAT 改了 AssemblyName

猜測是deploy ClickOnce 時

想同時deploy PROD 、 UAT 

那就需要改名稱,不然同名不能重複安裝 一個UAT,一個PROD 在同一電腦上

winForm.csproj

  <PropertyGroup>

    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

    <ProjectGuid>XXX</ProjectGuid>

    <OutputType>WinExe</OutputType>

    <AppDesignerFolder>Properties</AppDesignerFolder>

    <RootNamespace>Reminder.WinForm</RootNamespace>

    <AssemblyName>Reminder.WinForm</AssemblyName>


  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'UAT|AnyCPU'">

    ...

    <ProductName>UAT.XRayReminder</ProductName>

    <AssemblyName>Reminder.WinForm.UAT</AssemblyName>

  </PropertyGroup>


海豚找到 以下應該可行

<StartAction>Program</StartAction>

<StartProgram>C:\Path\To\Your\External\EnterpriseApp.exe</StartProgram>

<StartArguments>/debugMode</StartArguments>

<StartWorkingDirectory>C:\Path\To\Your\External\</StartWorkingDirectory>



另外

海豚看bin / obj 內build 完的config 真的有attribute / element duplicated

只要將 Insert 改成 Replace / Update



Reference

Google AI

search

VS xdt:Locator="Match(name)"


Answer

xdt:Locator="Match(name)" is an XML Document Transform (XDT) directive used in Visual Studio to locate and manipulate specific elements within XML files (like web.config or app.config) during project builds or deployments. It instructs the transformation engine to find an element in the target file whose name attribute exactly matches the name attribute in your transform file.


Code Example

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <connectionStrings>

    <add name="MyDB" 

         connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 

         xdt:Transform="SetAttributes" 

         xdt:Locator="Match(name)" />

  </connectionStrings>

</configuration>




https://learn.microsoft.com/en-us/previous-versions/aspnet/dd465326(v=vs.110)


https://www.youtube.com/watch?v=IpJOREDFTnY


https://jengting.blogspot.com/2020/10/VS-Configuration-Transform-AppConfig.html


Answer

When you pair this locator with a transformation attribute (such as xdt:Transform="SetAttributes" or xdt:Transform="Replace"), it modifies only the matched node. If multiple attributes are required for a precise match, they can be combined in a comma-delimited list (e.g., xdt:Locator="Match(name, providerName)").


https://www.zoeydc.com/Post/visual-studio-release-project-webconfig



Google AI

search

VS debug StartAction multiple


No comments:

Post a Comment