I'm trying to automate builds using the MSBuild API - "BuildManager".
The following code works fine for building solutions/projects but fails when it comes to publishing. The project publishes just fine when using the Visual Studio Publish page.
var collection = new ProjectCollection();
var parameters = new BuildParameters(collection);
parameters.Loggers = new List<ILogger> { Logger };
parameters.MaxNodeCount = Environment.ProcessorCount; //maxcpucount
var globalProperties = new Dictionary<string, string>();
globalProperties.Add("Configuration", "Debug");
globalProperties.Add("Platform", "AnyCPU");
globalProperties.Add("OutDir", binPath);
globalProperties.Add("OutputPath", publishPath);
globalProperties.Add("ApplicationVersion", version.ToString());
globalProperties.Add("GenerateBootstrapperSdkPath", @"C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\");
//Doesn't work!
globalProperties.Add("SignToolPath", @"C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\signtool.exe");
BuildManager.DefaultBuildManager.ResetCaches();
var buildRequest = new BuildRequestData(projectFile.FileInfo.FullName, globalProperties, "4.0", new[] { "Rebuild", "Publish" }, null);
var buildResult = BuildManager.DefaultBuildManager.Build(parameters, buildRequest);
If I run this code, it fails with the following error:
An error occurred while signing: SignTool.exe not found.
As you can see I'm adding the global property called "GenerateBootstrapperSdkPath", which if its not there leads to this error:
Could not find required file 'setup.bin' in 'C:\PathToProject\Engine'.
This seems to be a vicious cycle, as soon as I specify a path for the bootstrapper, it can't find the SignTool.exe, if I don't it can't find the setup.bin.
Unfortunately the global property "SignToolPath" doesn't seem to do anything.
Any Ideas?
There was an old problem of locating bootstrapper by MSBuild which could be solved by creating registry key:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\GenericBootstrapper\4.0]
@="0"
"Path"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bootstrapper\\"
Just set it to your SDK version and try again. Or perhaps use the path to your bootstrapper in BuildManager code based on the above one instead of:
C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\
According to one of old blog entries the following registry values are resolved in search for the bootstrapper path and finally your local project folder under the Engine sub folder is checked and when not found MSBuild throws MSB3147 error:
HKLM\Software\Microsoft\GenericBootstrapper\<.NET Tools Version>\
HKLM \Software\Microsoft.NetFramework\SDKInstallRoot\Bootstrapper
HKLM \Software\Microsoft\VisualStudio\\InstallDir\Bootstrapper
Team build for ClickOnce application with bootstrapper
I understand from your description that finding solution to bootstrapper location would solve your problem since in that configuration you did not observe any SignTool.exe problems.