如何完全摆脱web.config中的"$(ReplacableToken ...)"

Can*_*ğlu 55 publish web-config visual-studio-2010 visual-studio

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

在您说:是的之前,我知道我可以从原始目录中复制原始web.config,但我不想处理这个问题,我想在我测试时单击一下完成它发布包并经常重新创建包.

And*_*que 103

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

<AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
Run Code Online (Sandbox Code Playgroud)

我在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>
Run Code Online (Sandbox Code Playgroud)

  • 感谢您的解决方案 - 任何想法*为什么*我们必须这样做? (2认同)
  • @Mustafakidd 它与在构建项目(使用 MSBuild)期间调用的 msdeploy 打包有关。仅在部署时才应替换 ReplacableToken(使用 .csproj/.vsproj 中的 TransformXml 任务。更多信息在这里:http://stackoverflow.com/questions/4750153/transforming-files-with-msdeploy) (2认同)

drz*_*aus 16

我不得不做接受的答案所说的,而是在Properties/PublishProfiles/__THEPROFILE__.pubxml文件而不是.csproj文件中.

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


Rys*_*gan 5

当我尝试根据Travis Illig指令在外部为WiX设置创建Web项目包时,我遇到了类似的问题.我通过添加到以下内容解决了它:AutoParameterizationWebConfigConnectionStrings=FalseMSBuild/@Properties

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

  • +1这是针对此特定情况的适当解决方案,因为它不涉及修改已部署项目的配置,仅涉及部署逻辑. (2认同)