【问题标题】:MSBuild using BuildManager cannot find bootstrapper path or SignTool.exe使用 BuildManager 的 MSBuild 找不到引导程序路径或 SignTool.exe
【发布时间】:2017-10-23 16:32:20
【问题描述】:

我正在尝试使用 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\Engine'。

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

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

有什么想法吗?

【问题讨论】:

  • 同时,在假设存在各种绝对路径的情况下,明智地使用 if (File.Exists(....)) 会很好。

标签: c# msbuild signtool buildmanager


【解决方案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\

根据旧博客条目之一,在搜索引导程序路径时解析以下注册表值,最后检查引擎子文件夹下的本地项目文件夹,当未找到时,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 问题。

【讨论】:

  • 谢谢,你是对的,这与错误的注册表项或他们指向的 SDK 不存在有关。
猜你喜欢
  • 2013-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-25
  • 1970-01-01
  • 2011-10-22
相关资源
最近更新 更多