【问题标题】:How to get rid of "$(ReplacableToken...)" in web.config completely如何完全摆脱 web.config 中的“$(ReplacableToken...)”
【发布时间】:2011-11-04 16:20:22
【问题描述】:

我正在创建一个可发布的包,当我导航到obj\Debug\Package\PackageTmp 目录时,我看到 web.config 的连接字符串被替换为一个可替换的令牌,我根本不希望这样。我不会使用发布批处理文件或任何东西,我将复制目录中的文件(我使用发布包系统只是为了在测试我的项目并获得我的项目的新/原始文件树)我不想要那些 web.config 令牌和转换等,我只希望我的 web.config 文件像任何其他文件一样被复制。我该如何做到这一点?我已经看到了/p:AutoParameterizationWebConfigConnectionStrings=False 用于命令行的方法,但我没有使用命令行,而是使用 GUI 来创建包。如何阻止 web.config 将连接字符串更改为令牌?

在你说之前:是的,我知道我可以从我的原始目录复制原始 web.config,但我不想处理这个和那个,我想通过单击完成它,因为我正在测试发布包并经常重新创建包。

【问题讨论】:

    标签: visual-studio-2010 visual-studio web-config publish


    【解决方案1】:

    您必须编辑您的 .csproj 文件,并在 Debug PropertyGroup 中添加以下内容:

    <AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
    

    我的 Project.csproj 中的 ReleaseReleaseCERT 配置有以下内容(我只添加了 AutoParameterizationWebConfigConnectionStrings 行):

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '**Release**|AnyCPU' ">
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <OutputPath>bin\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <!-- add the following line to avoid ConnectionString tokenization -->
        <AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)' == '**ReleaseCERT**|AnyCPU'">
        <OutputPath>bin\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <Optimize>true</Optimize>
        <DebugType>pdbonly</DebugType>
        <PlatformTarget>AnyCPU</PlatformTarget>
        <ErrorReport>prompt</ErrorReport>
        <!-- add the following line to avoid ConnectionString tokenization -->
        <AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
    </PropertyGroup>
    

    【讨论】:

    • 感谢您的解决方案 - 知道为什么我们必须这样做吗?
    • @Mustafakidd 它与构建项目时调用的 msdeploy 打包相关(使用 MSBuild)。仅在部署时才应替换 ReplacableToken(使用 .csproj/.vsproj 中的 TransformXml 任务。更多信息:stackoverflow.com/questions/4750153/…
    • 一个更简单的解决方案可能是将虚拟 conn 字符串转换添加到 Web.Debug.config 或 Web.Release.config。
    • @Justin 当你有一个 ConnectionString 时,在原始 Web.config 或其中一种转换(Web.Debug.config、Web.Release.config 等)中,该令牌就会出现。就我而言,每个转换配置都有不同的 ConnectionStrings。
    • 您也可以将此设置保留在您的 pubxml 文件中
    【解决方案2】:

    我必须按照accepted answer 所说的去做,而是在Properties/PublishProfiles/__THEPROFILE__.pubxml 文件中而不是.csproj 文件中。

    (这可能是因为我使用的是 VS2012?)

    【讨论】:

    • VS 2015 也是如此。
    • VS 2017 也是如此。
    【解决方案3】:

    当我尝试根据Travis Illig instructions 在外部为 WiX 设置创建 Web 项目包时,我遇到了类似的问题。我通过将AutoParameterizationWebConfigConnectionStrings=False 添加到MSBuild/@Properties 来解决它:

    <MSBuild Projects="%(ProjectReference.FullPath)"
             Targets="Package"
             Properties="Configuration=$(Configuration);Platform=AnyCPU;AutoParameterizationWebConfigConnectionStrings=False"
             Condition="'%(ProjectReference.WebProject)'=='True'"
    

    【讨论】:

    • +1 对于这种特殊情况,这是合适的解决方案,因为它不涉及修改已部署项目的配置,只涉及部署逻辑。
    【解决方案4】:

    我必须在我的Project.csproj 文件的Release 条件部分添加以下内容:

    <InsertAdditionalWebCofigConnectionStrings>False</InsertAdditionalWebCofigConnectionStrings>
    

    【讨论】:

    • 没有解决问题。我认为您提供的 XML 标记可能拼写错误。似乎应该这样拼写... InsertAdditionalWebConfigConnectionStrings,而不是 InsertAdditionalWebCofigConnectionStrings 不管怎样,这对我不起作用。
    猜你喜欢
    • 2016-05-24
    • 2014-08-11
    • 2011-09-15
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 2023-03-06
    相关资源
    最近更新 更多