Issue with clickonce bootstrapper and msbuild

2020-02-19 10:19发布

问题:

I have a CruiseControl .NET build server running on Windows Server 2003, and I am trying to build and publish my ClickOnce application using msbuild.

Everything is working fine, except when I enable the bootstrapper of my ClickOnce application. When this happens, I get the following error in the DeploymentGenerateBootstrapper target:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (3939,9):

error MSB3147: 

Could not find required file 'setup.bin' in 'E:\Projects\src\TestProject\Engine'.

.NET Framework 3.5 SP1 and 4 and latest Windows SDK for both are installed on the server, but the bootstrapper folder in C:\Program Files\Microsoft SDKs\Windows\versionNo\ does not exist. I tried copying the files from my workstation machine with no luck.

I do not want to install Visual Studio on server and only install the necessary SDKs.

I have also tried copying the bootsrapper folder from my machine

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper

C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bootstrapper

to build server but no luck.

Any ideas?

回答1:

You will also have to add the associated key and value to the registry to allow MSBuild to find the path to the Bootstrapper folder. I can confirm that this has worked for me using the following regedit.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\GenericBootstrapper\4.0]
@="0"
"Path"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bootstrapper\\"

Update: According to Emma's TFS Blog it appears the following registry values are checked in order to find the bootstrapper path and if not found looks in your local project folder under the Engine sub folder and then bails with the MSB3147 error if not found there.

  1. HKLM\Software\Microsoft\GenericBootstrapper\<.NET Tools Version>\
  2. HKLM \Software\Microsoft.NetFramework\SDKInstallRoot\Bootstrapper
  3. HKLM \Software\Microsoft\VisualStudio\\InstallDir\Bootstrapper

Reminder: Also remember that there is a 32-bit and a 64-bit registry so be sure to add this value to the same registry that your tools will be accessing.

In the meantime I've also created a feature request to get a more reasonable solution for this issue. Please vote on my feature request to get Microsoft to take a look at it.

BTW, here are a few more links about this issue:

  • http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/7672078f-f2bd-4142-b8a9-740c2a8a5ae7
  • http://social.msdn.microsoft.com/Forums/en/msbuild/thread/6964ba78-5b66-4cd1-bdd1-b31edb76b96a
  • http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/97ac8717-daf7-4554-8dfa-8a63da47a17d
  • MSBuild: error MSB3147: Could not find required file 'setup.bin'
  • https://connect.microsoft.com/VisualStudio/feedback/details/361924/remove-bootstrapper-from-microsoft-sdks-directory
  • http://blogs.msdn.com/b/emmamou/archive/2009/04/08/team-build-for-clickonce-application-with-bootstrapper.aspx?CommentPosted=true#commentmessage


回答2:

You can also pass the location of the bootstrapper packages to the common Publish target like this:

<PropertyGroup>
     <BootstrapperSdkPath>C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bootstrapper</BootstrapperSdkPath>
</PropertyGroup>

and then

<Target Name="Publish">
    <MSBuild Targets="publish" ... Properties="GenerateBootstrapperSdkPath=$(BootstrapperSdkPath); ..."/>
</Target>


回答3:

I struggled with the same problem on my win7 x64 machine. I have not installed Visual Studio and tried to build and publish a .NET 4.5 WPF solution. I had to add the following keys to the registry

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\GenericBootstrapper\11.0]
"Path"="C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1A\\Bootstrapper\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\GenericBootstrapper\4.0]
"Path"="C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1A\\Bootstrapper\\"

You also need to copy the Bootstrapper folders from your dev machine. This blogpost directed me in the right direction http://www.wiktorzychla.com/2013/11/msb3147-could-not-find-required-file-on.html



回答4:

I had a similar issue to this but in my case I do have Visual Studio installed on the box, and publishing from Visual Studio works fine. When publishing from the command line with msbuild.exe, the build failed with aforementioned error "MSB3147 Could not find required file 'setup.bin'".

The solution was to explicitly specify what version of Visual Studio to use during build.

<MSBuild
  Projects="MyProject.csproj"
  Targets="publish"
  Properties="Configuration=Release;PublishUrl=C:\AnyFolder;VisualStudioVersion=12.0"/>

I have Visual Studio 2013 on a Win7 x64 machine. My reading of the problem is that MSBuild was looking in the wrong place in the registry. By explicitly telling MS Build to use VS 12.0, it picked the correct registry location entry and consequently the correct path to BootstrapperSdkPath.



回答5:

I was able to fix this problem by pointing to MSBuild.exe from this location

C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe

Previously I was pointing to

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe



回答6:

Hi I know this answer its soooooo late but just in case

I had to add the Path prop to the task, with the Path where the bootstrapper its located, in my case I used Visual Studio 2015 so the Path is:

**Program Files(x86)\Microsoft Visual Studio 14.0\SDK\Boostrapper**

MSBuild has a Task GenerateBootstrapper in my case

    <GenerateBootstrapper> 
       AplicationFile="$(AppName)"
       ApplicationName=..
       ApplicationUrl=..
       BootstrapperItems=..
       Culture=..
       ApplicationUrl=.. 
       Path="Program Files(x86)\Microsoft Visual Studio 14.0\SDK\Boostrapper\"
    </GenerateBootstrapper>

with this the MSBuild is able to recognize and generate the file

Now i'm stucked with the .net 4 bootstrapper but guess is another story...



回答7:

I experienced this same error via my TeamCity build server. The cause in my case was that I was running an MSBuild task against my .sln file, with a 'MyProject:publish' target. In this case, the solution+projecth had been updated to target .NET v4.5, but the build server was still configured to use MSBuild Tools 4.0 and .NET v4.0.

Took me a little while to work out the inconsistency between working and non-working branch builds.



回答8:

I added this line to script. It helped.

call "%VS120COMNTOOLS%vsvars32.bat"

Visual Studio 2013, SDK v8.1A.



回答9:

Just struggled with this myself - I chose to commit the bootstrapper files to source control. It is possible to override the path to bootstrappers, just provide /p:GenerateBootstrapperSdkPath=.build\Bootstrapper

Then no need to modify registry - and the added benefit that the build is now self-contained.

Only "problem" is that I have to manually copy the Bootstrapper files into source control. In my case (VStudio2015), this meant copying the files from C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper