Search code examples
winformsclickonceapp-configpublishingconfig-transformation

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. 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. Multiple items cannot be passed into a parameter of type "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. 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".

I tried removing the clickonce certificate and installing a new one with no difference in symptoms.

Note this is a Windows Forms application, not a web app. The transforms were created using the Configuration Transform extension (works the same as 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:

<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. 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.


Solution

  • Resolved: these symptoms were caused by Microsoft.Bcl not playing well with config transforms and ClickOnce publishing together. This app was created with .NET 4 using Bcl in order to use the async/await pattern while running on old XP machines. 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. With Bcl gone, the issue is completely resolved. (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).