简体   繁体   English

Winform ClickOnce发布失败,app.config转换

[英]Winforms ClickOnce publish fails with app.config transforms

I added app.config transforms to an existing Windows Forms client application that uses ClickOnce publishing, and now it will not publish. 我将app.config转换添加到使用ClickOnce发布的现有Windows窗体客户端应用程序,现在它不会发布。 Error message: 错误信息:

"obj\\Release\\Client.csproj.App.config;obj\\Release\\MyAppName.exe.config" is an invalid value for the "ConfigFile" parameter of the "GenerateApplicationManifest" task. “obj \\ Release \\ Client.csproj.App.config; obj \\ Release \\ MyAppName.exe.config”是“GenerateApplicationManifest”任务的“ConfigFile”参数的无效值。 Multiple items cannot be passed into a parameter of type "Microsoft.Build.Framework.ITaskItem" 无法将多个项目传递给“Microsoft.Build.Framework.ITaskItem”类型的参数

When I uncheck "Enable ClickOnce security settings" (project properties > Security), the project will build and run from Visual Studio 2015 without this error, but when I try to publish using ClickOnce, the error returns. 当我取消选中“启用ClickOnce安全设置”(项目属性>安全性)时,项目将在没有此错误的情况下从Visual Studio 2015构建和运行,但是当我尝试使用ClickOnce发布时,错误将返回。 Enabling security results in the project not building at all. 启用安全性会导致项目根本无法构建。 Either way, the error is the same. 无论哪种方式,错误都是一样的。

The app.config is set to to "Copy Always". app.config设置为“始终复制”。

I tried removing the clickonce certificate and installing a new one with no difference in symptoms. 我尝试删除clickonce证书并安装一个没有症状差异的新证书。

Note this is a Windows Forms application, not a web app. 请注意,这是一个Windows窗体应用程序,而不是Web应用程序。 The transforms were created using the Configuration Transform extension (works the same as SlowCheetah). 转换是使用Configuration Transform扩展创建的(与SlowCheetah的工作方式相同)。 I've used this setup for other applications successfully, and so far haven't found a difference in the settings between this app and the successful ones. 我已经成功地将此设置用于其他应用程序,并且到目前为止还未发现此应用程序与成功应用程序之间的设置存在差异。

This section of the .csproj file seems to be related to the issue: .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>

Another post suggested removing the ItemGroup node. 另一篇文章建议删除ItemGroup节点。 When I do this, the project builds and runs in VS, and is able to be published to a test location, but the app.config transform doesn't happen. 当我这样做时,项目在VS中构建和运行,并且能够发布到测试位置,但app.config转换不会发生。

Resolved: these symptoms were caused by Microsoft.Bcl not playing well with config transforms and ClickOnce publishing together. 已解决:这些症状是由Microsoft.Bcl引起的,无法与config变换和ClickOnce一起发布。 This app was created with .NET 4 using Bcl in order to use the async/await pattern while running on old XP machines. 这个应用程序是使用Bcl使用.NET 4创建的,以便在旧的XP机器上运行时使用async / await模式。 Our users have upgraded to Windows 7 & 10 since then, so I was able to upgrade the app to .NET 4.5.2 and remove the Bcl packages. 从那时起,我们的用户已升级到Windows 7和10,因此我能够将应用程序升级到.NET 4.5.2并删除Bcl软件包。 With Bcl gone, the issue is completely resolved. 随着Bcl的消失,问题彻底解决了。 (There may be some kind of hack to get Bcl to work correctly with config transforms and clickonce, but since I was able to upgrade, am not pursuing it further). (可能有某种黑客攻击让Bcl在配置转换和clickonce中正常工作,但由于我能够升级,所以不再追求它)。

If the accepted answer does not work for you (like it did not for me). 如果接受的答案对你不起作用(就像它不适合我)。 Please see the solution to this 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)" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM