由于缺少原始 UI.exe 文件,不同版本的 ClickOnce 应用程序导致崩溃
Different versions of ClickOnce application cause crash due to missing original UI.exe file
我遇到了 ClickOnce 版本问题:
- 我们需要在每台机器上通过 ClickOnce 安装程序的三个版本,每个版本都有不同的设置:Production、Pilot 和 Test
- 我们所做的是使用一个自编程的发布管理器,它使用 MSBuild
将每个版本部署在不同的网络驱动器位置
- 每个版本的安装都很好,但是当 运行.
时程序崩溃了
- ApplicationName 在 运行ning MSBuild 时更改,我发现该应用程序仍在寻找原始 UI.exe,而应用程序的名称已更改为例如UITest.exe
- 如果我将 UI.exe 复制到安装文件夹,然后 运行 UITest.exe 程序将正常运行。
我错过了什么?我怎样才能去掉原来需要的UI.exe?
背景信息:
为了能够通过 MSBuild 发布三个不同的版本,我们使用了一个额外的“.target”文件,该文件在构建 属性 组之后在 UI.csproj 中实现,如下所示:
<Import Project="CustomBuild.targets" />
CustomBuild.targets 文件如下所示:
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishType>none</PublishType>
</PropertyGroup>
<Choose>
<When Condition="'$(PublishType)' == 'production'">
<PropertyGroup>
<PublishUrl>\netapp1\users\ClickOnce\Production\</PublishUrl>
<InstallUrl>\netapp1\users\ClickOnce\Production\</InstallUrl>
<PublishDir>\netapp1\users\ClickOnce\Production\</PublishDir>
<ProductName>UI Production</ProductName>
<AssemblyName>UIProd</AssemblyName> -- AssemblyName is changed here
<UIExchangeSettingsPath>..\_UIExchangeSettings\Prod</UIExchangeSettingsPath>
</PropertyGroup>
</When>
<When Condition=" '$(PublishType)' == 'pilot' ">
<PropertyGroup>
<PublishUrl>\netapp1\users\ClickOnce\Pilot\</PublishUrl>
<InstallUrl>\netapp1\users\ClickOnce\Pilot\</InstallUrl>
<PublishDir>\netapp1\users\ClickOnce\Pilot\</PublishDir>
<ProductName>UI Pilot</ProductName>
<AssemblyName>UIPilot</AssemblyName> -- AssemblyName is changed here
<UIExchangeSettingsPath>..\_UIExchangeSettings\Pilot</UIExchangeSettingsPath>
</PropertyGroup>
</When>
<When Condition=" '$(PublishType)' == 'test' ">
<PropertyGroup>
<PublishUrl>\netapp1\users\ClickOnce\Test\</PublishUrl>
<InstallUrl>\netapp1\users\ClickOnce\Test\</InstallUrl>
<PublishDir>\netapp1\users\ClickOnce\Test\</PublishDir>
<ProductName>UI Test</ProductName>
<AssemblyName>UITest</AssemblyName> -- AssemblyName is changed here
<UIExchangeSettingsPath>..\_UIExchangeSettings\Test</UIExchangeSettingsPath>
</PropertyGroup>
</When>
</Choose>
</Project>
然后在批处理文件中调用 MSBuild Process,如下所示:
@echo off
set branch=%1
set publishtype=%2
echo Rebuilding UI project and publishing as new %publishtype% version...
>output.txt (
"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\bin\MSBuild.EXE" "C:\Projects\%branch%\UI" /p:SolutionDir="C:\Projects\%branch%\" /p:PlatformTarget=x86 /p:Configuration=Release /p:PublishType=%publishtype% /t:rebuild /t:publish
)
当 运行 安装程序时,它们崩溃并在 windows 事件日志中显示以下异常:
Log Name: Application
Source: .NET Runtime
Date: 11.11.2020 10:02:58
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: vw8-te-012.***.intranet
Description:
Application: UIProd.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
at System.Reflection.RuntimeAssembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
at System.Reflection.RuntimeAssembly.nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
at System.Reflection.Assembly.Load(System.Reflection.AssemblyName)
at System.Windows.Navigation.BaseUriHelper.GetLoadedAssembly(System.String, System.String, System.String)
at MS.Internal.AppModel.ResourceContainer.GetResourceManagerWrapper(System.Uri, System.String ByRef, Boolean ByRef)
at MS.Internal.AppModel.ResourceContainer.GetPartCore(System.Uri)
at System.IO.Packaging.Package.GetPartHelper(System.Uri)
at System.IO.Packaging.Package.GetPart(System.Uri)
at System.IO.Packaging.PackWebResponse+CachedResponse.GetResponseStream()
at System.IO.Packaging.PackWebResponse.GetResponseStream()
at System.IO.Packaging.PackWebResponse.get_ContentType()
at MS.Internal.WpfWebRequestHelper.GetContentType(System.Net.WebResponse)
at MS.Internal.WpfWebRequestHelper.GetResponseStream(System.Net.WebRequest, MS.Internal.ContentType ByRef)
at System.Windows.ResourceDictionary.set_Source(System.Uri)
at System.Windows.Baml2006.WpfSharedBamlSchemaContext+<>c.<Create_BamlProperty_ResourceDictionary_Source>b__342_0(System.Object, System.Object)
at System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(System.Object, System.Object)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Xaml.XamlMember, System.Object, System.Object)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Object, System.Xaml.XamlMember, System.Object)
Exception Info: System.Windows.Markup.XamlParseException
at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
at System.Windows.Application.LoadComponent(System.Object, System.Uri)
at UI.App.InitializeComponent()
at UI.App.Main()
和
Log Name: Application
Source: Application Error
Date: 11.11.2020 10:02:58
Event ID: 1000
Task Category: (100)
Level: Error
Keywords: Classic
User: N/A
Computer: vw8-te-012.***.intranet
Description:
Faulting application name: UIProd.exe, version: 1.0.0.0, time stamp: 0x5faba858
Faulting module name: KERNELBASE.dll, version: 6.3.9600.17031, time stamp: 0x53088860
Exception code: 0xe0434352
Fault offset: 0x00014dbd
Faulting process ID: 0x3594
Faulting application start time: 0x01d6b80972f79f7d
Faulting application path: C:\Users\***\AppData\Local\Apps.0\XNQORKVG.2DTA4N7BAY.11G\uipr..tion_e9badd1d426758be_0001.0001_0a1650216431b128\UIProd.exe
Faulting module path: C:\Windows\SYSTEM32\KERNELBASE.dll
Report ID: b1090c1f-23fc-11eb-82ef-0050568fb707
Faulting package full name:
Faulting package-relative application ID:
原来是对 App.xaml 中的资源字典的引用导致了问题。
实施错误:
<ResourceDictionary Source="pack://application:,,,/UI;component/Resources/PlcBuildResources.xaml" />
更正的实施:
<ResourceDictionary Source="../Resources/PlcBuildResources.xaml"/>
经验教训:在引用中使用程序集名称引用资源字典或其他文件时要小心。如果像我这样在通过 MSBuild 构建时更改了程序集名称,将找不到引用的文件并导致应用程序崩溃。
我遇到了 ClickOnce 版本问题:
- 我们需要在每台机器上通过 ClickOnce 安装程序的三个版本,每个版本都有不同的设置:Production、Pilot 和 Test
- 我们所做的是使用一个自编程的发布管理器,它使用 MSBuild 将每个版本部署在不同的网络驱动器位置
- 每个版本的安装都很好,但是当 运行. 时程序崩溃了
- ApplicationName 在 运行ning MSBuild 时更改,我发现该应用程序仍在寻找原始 UI.exe,而应用程序的名称已更改为例如UITest.exe
- 如果我将 UI.exe 复制到安装文件夹,然后 运行 UITest.exe 程序将正常运行。
我错过了什么?我怎样才能去掉原来需要的UI.exe?
背景信息:
为了能够通过 MSBuild 发布三个不同的版本,我们使用了一个额外的“.target”文件,该文件在构建 属性 组之后在 UI.csproj 中实现,如下所示:
<Import Project="CustomBuild.targets" />
CustomBuild.targets 文件如下所示:
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishType>none</PublishType>
</PropertyGroup>
<Choose>
<When Condition="'$(PublishType)' == 'production'">
<PropertyGroup>
<PublishUrl>\netapp1\users\ClickOnce\Production\</PublishUrl>
<InstallUrl>\netapp1\users\ClickOnce\Production\</InstallUrl>
<PublishDir>\netapp1\users\ClickOnce\Production\</PublishDir>
<ProductName>UI Production</ProductName>
<AssemblyName>UIProd</AssemblyName> -- AssemblyName is changed here
<UIExchangeSettingsPath>..\_UIExchangeSettings\Prod</UIExchangeSettingsPath>
</PropertyGroup>
</When>
<When Condition=" '$(PublishType)' == 'pilot' ">
<PropertyGroup>
<PublishUrl>\netapp1\users\ClickOnce\Pilot\</PublishUrl>
<InstallUrl>\netapp1\users\ClickOnce\Pilot\</InstallUrl>
<PublishDir>\netapp1\users\ClickOnce\Pilot\</PublishDir>
<ProductName>UI Pilot</ProductName>
<AssemblyName>UIPilot</AssemblyName> -- AssemblyName is changed here
<UIExchangeSettingsPath>..\_UIExchangeSettings\Pilot</UIExchangeSettingsPath>
</PropertyGroup>
</When>
<When Condition=" '$(PublishType)' == 'test' ">
<PropertyGroup>
<PublishUrl>\netapp1\users\ClickOnce\Test\</PublishUrl>
<InstallUrl>\netapp1\users\ClickOnce\Test\</InstallUrl>
<PublishDir>\netapp1\users\ClickOnce\Test\</PublishDir>
<ProductName>UI Test</ProductName>
<AssemblyName>UITest</AssemblyName> -- AssemblyName is changed here
<UIExchangeSettingsPath>..\_UIExchangeSettings\Test</UIExchangeSettingsPath>
</PropertyGroup>
</When>
</Choose>
</Project>
然后在批处理文件中调用 MSBuild Process,如下所示:
@echo off
set branch=%1
set publishtype=%2
echo Rebuilding UI project and publishing as new %publishtype% version...
>output.txt (
"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\bin\MSBuild.EXE" "C:\Projects\%branch%\UI" /p:SolutionDir="C:\Projects\%branch%\" /p:PlatformTarget=x86 /p:Configuration=Release /p:PublishType=%publishtype% /t:rebuild /t:publish
)
当 运行 安装程序时,它们崩溃并在 windows 事件日志中显示以下异常:
Log Name: Application
Source: .NET Runtime
Date: 11.11.2020 10:02:58
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: vw8-te-012.***.intranet
Description:
Application: UIProd.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
at System.Reflection.RuntimeAssembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
at System.Reflection.RuntimeAssembly.nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
at System.Reflection.Assembly.Load(System.Reflection.AssemblyName)
at System.Windows.Navigation.BaseUriHelper.GetLoadedAssembly(System.String, System.String, System.String)
at MS.Internal.AppModel.ResourceContainer.GetResourceManagerWrapper(System.Uri, System.String ByRef, Boolean ByRef)
at MS.Internal.AppModel.ResourceContainer.GetPartCore(System.Uri)
at System.IO.Packaging.Package.GetPartHelper(System.Uri)
at System.IO.Packaging.Package.GetPart(System.Uri)
at System.IO.Packaging.PackWebResponse+CachedResponse.GetResponseStream()
at System.IO.Packaging.PackWebResponse.GetResponseStream()
at System.IO.Packaging.PackWebResponse.get_ContentType()
at MS.Internal.WpfWebRequestHelper.GetContentType(System.Net.WebResponse)
at MS.Internal.WpfWebRequestHelper.GetResponseStream(System.Net.WebRequest, MS.Internal.ContentType ByRef)
at System.Windows.ResourceDictionary.set_Source(System.Uri)
at System.Windows.Baml2006.WpfSharedBamlSchemaContext+<>c.<Create_BamlProperty_ResourceDictionary_Source>b__342_0(System.Object, System.Object)
at System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(System.Object, System.Object)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Xaml.XamlMember, System.Object, System.Object)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Object, System.Xaml.XamlMember, System.Object)
Exception Info: System.Windows.Markup.XamlParseException
at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
at System.Windows.Application.LoadComponent(System.Object, System.Uri)
at UI.App.InitializeComponent()
at UI.App.Main()
和
Log Name: Application
Source: Application Error
Date: 11.11.2020 10:02:58
Event ID: 1000
Task Category: (100)
Level: Error
Keywords: Classic
User: N/A
Computer: vw8-te-012.***.intranet
Description:
Faulting application name: UIProd.exe, version: 1.0.0.0, time stamp: 0x5faba858
Faulting module name: KERNELBASE.dll, version: 6.3.9600.17031, time stamp: 0x53088860
Exception code: 0xe0434352
Fault offset: 0x00014dbd
Faulting process ID: 0x3594
Faulting application start time: 0x01d6b80972f79f7d
Faulting application path: C:\Users\***\AppData\Local\Apps.0\XNQORKVG.2DTA4N7BAY.11G\uipr..tion_e9badd1d426758be_0001.0001_0a1650216431b128\UIProd.exe
Faulting module path: C:\Windows\SYSTEM32\KERNELBASE.dll
Report ID: b1090c1f-23fc-11eb-82ef-0050568fb707
Faulting package full name:
Faulting package-relative application ID:
原来是对 App.xaml 中的资源字典的引用导致了问题。
实施错误:
<ResourceDictionary Source="pack://application:,,,/UI;component/Resources/PlcBuildResources.xaml" />
更正的实施:
<ResourceDictionary Source="../Resources/PlcBuildResources.xaml"/>
经验教训:在引用中使用程序集名称引用资源字典或其他文件时要小心。如果像我这样在通过 MSBuild 构建时更改了程序集名称,将找不到引用的文件并导致应用程序崩溃。