Winforms ClickOnce 发布因 app.config 转换而失败

标签 winforms clickonce app-config publishing config-transformation

我添加了 app.config 转换为使用 ClickOnce 发布的现有 Windows 窗体客户端应用程序,但现在它不会发布。错误信息:

"obj\Release\Client.csproj.App.config;obj\Release\MyAppName.exe.config" is an invalid value for the "ConfigFile" parameter of the "GenerateApplicationManifest" task. Multiple items cannot be passed into a parameter of type "Microsoft.Build.Framework.ITaskItem"

当我取消选中“启用 ClickOnce 安全设置”(项目属性 > 安全性)时,项目将从 Visual Studio 2015 生成并运行,而不会出现此错误,但当我尝试使用 ClickOnce 发布时,错误又出现。启用安全性会导致项目根本无法构建。无论哪种方式,错误都是相同的。

app.config 设置为“始终复制”。

我尝试删除 clickonce 证书并安装新证书,症状没有任何差异。

请注意,这是 Windows 窗体应用程序,而不是 Web 应用程序。转换是使用 Configuration Transform 创建的扩展(与 SlowCheetah 工作方式相同)。我已成功将此设置用于其他应用程序,到目前为止,尚未发现此应用程序与成功应用程序之间的设置存在差异。

.csproj 文件的这一部分似乎与该问题相关:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
      <Target Name="AfterCompile" Condition="Exists('App.$(Configuration).config')">
        <!--Generate transformed app config in the intermediate directory-->
        <TransformXml Source="App.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="App.$(Configuration).config" />
        <!--Force build process to use the transformed configuration file from now on.-->
        <ItemGroup>
          <AppConfigWithTargetPath Remove="App.config" />
          <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
            <TargetPath>$(TargetFileName).config</TargetPath>
          </AppConfigWithTargetPath>
        </ItemGroup>
      </Target>

另一篇文章建议删除 ItemGroup 节点。当我这样做时,项目会在 VS 中构建并运行,并且能够发布到测试位置,但 app.config 转换不会发生。

最佳答案

如果接受的答案对您不起作用(就像对我不起作用一样)。请参阅此问题的解决方案question :

I ran into this same problem. What fixed it for me was changing the line in the transform from above

from

<AppConfigWithTargetPath Remove="app.config" />

to

<AppConfigWithTargetPath Remove="@(AppConfigWithTargetPath)" />

关于Winforms ClickOnce 发布因 app.config 转换而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44593380/

相关文章:

c# - 使用 System.Threading.Task 访问 winform 控件卡住

c# - 在 Visual studio 2015 中,设计器以 win 形式更改控件的属性,例如大小

.net - 签署 ClickOnce list 复选框保持默认为在发布时选中

deployment - 具有 Crystal Reports 前提条件的 ClickOnce 部署

关闭表单时出现 C# ArgumentOutOfRangeException

c# - 单击控件内的文本时,用户控件单击事件不起作用?

.net - 更新 app.config 部署后的奇怪行为

c# - ms access数据库受密码保护时如何编写连接字符串?

c# - Odbc 连接到 .tps 数据库不工作

.net - 如何在 VS 2008 项目中将 ConfigurationManager 用于 DEBUG 和 RELEASE 版本