【问题标题】:Building an installer for a C# project in VS2019 .NET 4.8 fails在 VS2019 .NET 4.8 中为 C# 项目构建安装程序失败
【发布时间】:2020-02-29 23:39:01
【问题描述】:

我在 VS2019 Enterprise 中使用 .NET 4.8 构建的解决方案中有一个 C# 项目,由于这是一个仅供内部使用的工具,1) 我将发布的构建日志将被编辑,2)我确切地知道将运行它的每台计算机的硬件和 .NET 版本,因为它们都与我自己的相同。

该程序集使用硬件密钥进行签名,因为我们使用白名单来确定哪些可以在所述笔记本电脑上运行,哪些不能运行,(所以我必须在本地构建它)并且我只构建 x64 是因为内存需求工具。 (是的,我已经看到它运行了,是的,它使用了超过 2GB 的 RAM,不,我对此无能为力。你只需要相信我的话。)

综上所述,我安装了 Microsoft 制造的扩展程序来尝试创建 MSI 安装程序,因为它需要尽可能易于安装,并且一直失败。输出如下。

    1>------ Rebuild All started: Project: MyCSProject, Configuration: Release x64 ------
    1>  MyCSProject -> C:\dev\Source\Repos\MySolution\MyCSProject\bin\x64\Release\MyCSProject.exe
    1>  Done Adding Additional Store
    1>  Successfully signed: C:\dev\Source\Repos\MySolution\MyCSProject\bin\x64\Release\MyCSProject.exe
    1>  
    ------ Starting pre-build validation for project 'MyCSProject Setup' ------ 
    ------ Starting pre-build validation for project 'MyCSProject Setup' ------ 
    ------ Starting pre-build validation for project 'MyCSProject Setup' ------ 
    WARNING: Unable to find dependency 'MICROSOFT.WINDOWSAPICODEPACK' (Signature='(null)' Version='1.1.0.0') of assembly 'Microsoft.WindowsAPICodePack.Shell.dll'
    WARNING: Unable to find dependency 'MICROSOFT.WINDOWSAPICODEPACK' (Signature='(null)' Version='1.1.0.0') of assembly 'Microsoft.WindowsAPICodePack.Shell.dll'
    WARNING: Unable to find dependency 'MICROSOFT.WINDOWSAPICODEPACK' (Signature='(null)' Version='1.1.0.0') of assembly 'Microsoft.WindowsAPICodePack.Shell.dll'
    ------ Pre-build validation for project 'MyCSProject Setup' completed ------
    ------ Pre-build validation for project 'MyCSProject Setup' completed ------
    ------ Pre-build validation for project 'MyCSProject Setup' completed ------
    2>------ Rebuild All started: Project: MyCSProject Setup, Configuration: Release ------
    2>------ Rebuild All started: Project: MyCSProject Setup, Configuration: Release ------
    2>------ Rebuild All started: Project: MyCSProject Setup, Configuration: Release ------
    Building file 'C:\dev\Source\Repos\MySolution\MyCSProject Setup\Release\MyCSProject Setup.msi'...
    Building file 'C:\dev\Source\Repos\MySolution\MyCSProject Setup\Release\MyCSProject Setup.msi'...
    Building file 'C:\dev\Source\Repos\MySolution\MyCSProject Setup\Release\MyCSProject Setup.msi'...
    WARNING: Xml validation did not pass for item 'Microsoft .NET Framework 4.8 (x86 and x64)' located at 'C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\DotNetFX48\product.xml'.
    WARNING: Xml validation did not pass for item 'Microsoft .NET Framework 4.8 (x86 and x64)' located at 'C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\DotNetFX48\product.xml'.
    WARNING: Xml validation did not pass for item 'Microsoft .NET Framework 4.8 (x86 and x64)' located at 'C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\DotNetFX48\product.xml'.
    WARNING: Xml Validation error in file 'C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\DotNetFX48\product.xml': The element 'InstallConditions' in namespace 'http://schemas.microsoft.com/developer/2004/01/bootstrapper' cannot contain text. List of possible elements expected: 'http://schemas.microsoft.com/developer/2004/01/bootstrapper:BypassIf http://schemas.microsoft.com/developer/2004/01/bootstrapper:FailIf'.
    WARNING: Xml Validation error in file 'C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\DotNetFX48\product.xml': The element 'InstallConditions' in namespace 'http://schemas.microsoft.com/developer/2004/01/bootstrapper' cannot contain text. List of possible elements expected: 'http://schemas.microsoft.com/developer/2004/01/bootstrapper:BypassIf http://schemas.microsoft.com/developer/2004/01/bootstrapper:FailIf'.
    WARNING: Xml Validation error in file 'C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\DotNetFX48\product.xml': The element 'InstallConditions' in namespace 'http://schemas.microsoft.com/developer/2004/01/bootstrapper' cannot contain text. List of possible elements expected: 'http://schemas.microsoft.com/developer/2004/01/bootstrapper:BypassIf http://schemas.microsoft.com/developer/2004/01/bootstrapper:FailIf'.
    WARNING: Two or more objects have the same target location ('[targetdir]\system.runtime.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.runtime.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.runtime.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.runtime.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.runtime.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.runtime.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.net.http.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.net.http.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.net.http.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.net.http.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.net.http.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.net.http.dll')
    ERROR: File 'MyCSProject.exe' of project output 'Primary output from MyCSProject (Active)' targeting 'AMD64' is not compatible with the project's target platform 'x86'
    ERROR: File 'MyCSProject.exe' of project output 'Primary output from MyCSProject (Active)' targeting 'AMD64' is not compatible with the project's target platform 'x86'
    ERROR: File 'MyCSProject.exe' of project output 'Primary output from MyCSProject (Active)' targeting 'AMD64' is not compatible with the project's target platform 'x86'
    WARNING: File 'MyCSProject.exe' of project output 'Primary output from MyCSProject (Active)' targeting 'x64' is not compatible with the project's target platform 'x86'
    WARNING: File 'MyCSProject.exe' of project output 'Primary output from MyCSProject (Active)' targeting 'x64' is not compatible with the project's target platform 'x86'
    WARNING: File 'MyCSProject.exe' of project output 'Primary output from MyCSProject (Active)' targeting 'x64' is not compatible with the project's target platform 'x86'
    Build process cancelled
    ========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========

(如果我可以指定一种语言可以使构建日志更易于阅读,请务必告诉我。我也可以发布日志提到的Product.xml 的内容,但因为它是97 行,除非必要,否则我不会。)

旁注,我什至没有使用任何 HTTP,(这严格来说是一个 Windows 窗体程序,)所以我不知道为什么要包含 system.net.http.dll。该工具仍在开发中,所以毫无疑问,我必须在完成之前重新构建几次,但我只是想以一种我可以在他们的笔记本电脑上使用的格式来获得这个东西,因为我们是风靡全国。

那么为什么不建立呢?我发现这方面的文档很少,尤其是最近的任何文档。 应该发生什么,正如前几行所示,应该构建一个 MSI 来安装我的 exe 和任何无法滚动到 EXE 中的 DLL。

(FWIW,我也尝试在 VS 中使用 Publish 选项,但随后它抱怨 .manifyt 格式错误,并且它仍然没有创建我正在寻找的那个“一劳永逸”的安装程序。)

更新

Gonzix 的回答消除了错误,但我仍然有一些警告。这些有什么大不了的吗?我可以按原样安全部署,还是需要做其他事情?

    WARNING: Unable to find dependency 'MICROSOFT.WINDOWSAPICODEPACK' (Signature='(null)' Version='1.1.0.0') of assembly 'Microsoft.WindowsAPICodePack.Shell.dll'
    ------ Pre-build validation for project 'MyCSProject Setup' completed ------
    2>------ Rebuild All started: Project: MyCSProject Setup, Configuration: Release ------
    Building file 'C:\dev\Source\Repos\MySolution\MyCSProject Setup\Release\MyCSProject Setup.msi'...
    WARNING: Xml validation did not pass for item 'Microsoft .NET Framework 4.8 (x86 and x64)' located at 'C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\DotNetFX48\product.xml'.
    WARNING: Xml Validation error in file 'C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\DotNetFX48\product.xml': The element 'InstallConditions' in namespace 'http://schemas.microsoft.com/developer/2004/01/bootstrapper' cannot contain text. List of possible elements expected: 'http://schemas.microsoft.com/developer/2004/01/bootstrapper:BypassIf http://schemas.microsoft.com/developer/2004/01/bootstrapper:FailIf'.
    WARNING: Two or more objects have the same target location ('[targetdir]\system.net.http.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.net.http.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.runtime.dll')
    WARNING: Two or more objects have the same target location ('[targetdir]\system.runtime.dll')

我主要担心的是某些决斗 DLL 情况,最终用户的计算机会以某种方式混淆,或者导致执行白名单的工具尖叫。我知道我的笔记本电脑已针对该工具进行了配置以减少尖叫(否则 VS 将永远不会运行),因此我希望出现零警告,而不仅仅是零错误...

TL;DR 是我仍然遇到问题的警告吗?在什么情况下它们会成为问题?

【问题讨论】:

  • 或许你可以尝试先添加所有项目输出,然后手动移除依赖节点中添加的依赖。
  • 没有时间正确回答,但这些文件是 .NET 框架的一部分,不应重新分发。按照建议手动添加您需要的文件,并删除任何从臀部拍摄并添加不必要的东西的“自动魔法”。还要确保构建 x64 位版本,因为这是您需要的(内存)。也许考虑使用更好的MSI creation tool。并输入WiX quick start
  • @SteinÅsmul 我研究了这些工具,但我必须经过一个漫长的过程才能请求在我的笔记本电脑上运行它们的权限:(
  • “我发现这方面的文档很少,尤其是最近的。”似乎最终 MS 放弃了它创建的每个 API。您是否正在构建大量此类内部应用程序?如果是这样,你可以考虑做你自己的安装程序。并非微不足道,但可能值得从 MSI 跑步机上下来。我是为商业应用做的,所以有可能。
  • 你真的应该考虑迁移到另一种技术,blog.lextudio.com/…

标签: c# build windows-installer visual-studio-2019 visual-studio-setup-proje


【解决方案1】:

如果有人仍然需要它,xml 中有错字,您需要删除 C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\DotNetFX48\Product.xml 文件第 45 行的 - 字符。

【讨论】:

  • 微软为什么不解决这个问题?哎呀!我花了很长时间才找到这个修复程序。谢谢!
【解决方案2】:

如果“Microsoft 制造”扩展是指 Microsoft Visual Studio 安装程序扩展,则应单击安装项目并查找项目属性。有一个名为“TargetPlaform”的属性默认指向 x86。不知道是不是这样,但这为我解决了问题。

【讨论】:

  • 太棒了!这让我达到了 85%。针对我仍然遇到的错误编辑了原始问题。
【解决方案3】:

Xml 验证未通过项“Microsoft .NET Framework 4.8(x86 和 x64)

错误可能与this有关。

某种拼写错误。 您可以使用管理员权限手动更改该文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    • 1970-01-01
    • 2010-10-25
    • 2020-04-26
    • 2022-06-28
    相关资源
    最近更新 更多