使用BuildManager的MSBuild找不到bootstrapper路径或SignTool.exe

时间:2017-10-23 16:32:20

标签: c# msbuild signtool buildmanager

我正在尝试使用MSBuild API自动化构建 - “BuildManager”。

以下代码适用于构建解决方案/项目,但在发布方面则失败。 使用Visual Studio发布页面时,该项目发布得很好。

            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);

如果我运行此代码,则会因以下错误而失败:

  

签名时发生错误:找不到SignTool.exe。

正如您所看到的,我正在添加名为“GenerateBootstrapperSdkPath”的全局属性,如果它不存在,则会导致此错误:

  

找不到所需的文件'setup.bin'   'C:\ PathToProject \引擎'

这似乎是一个恶性循环,只要我为引导程序指定路径,它就找不到SignTool.exe,如果我不能找不到setup.bin。

不幸的是,全局属性“SignToolPath”似乎没有做任何事情。

任何想法?

1 个答案:

答案 0 :(得分:1)

MSBuild定位引导程序有一个老问题,可以通过创建注册表项来解决:

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

只需将其设置为SDK版本,然后重试。或者在BuildManager代码中使用基于上述代码的引导程序的路径而不是:

C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\

根据旧博客条目之一,解析以下注册表值以搜索引导程序路径,最后检查Engine子文件夹下的本地项目文件夹,当找不到时MSBuild抛出MSB3147错误:

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

我从您的描述中了解到,找到引导程序位置的解决方案可以解决您的问题,因为在该配置中您没有观察到任何SignTool.exe问题。