如何解决不同版本的ClickOnce应用程序由于缺少原始UI.exe文件而导致崩溃
我对ClickOnce版本有疑问:
- 我们需要在每台计算机上通过ClickOnce安装三个版本的程序,每个版本具有不同的设置:生产,试验和测试
- 我们要做的是使用一个自编程的发布管理器,该管理器使用MSBuild将每个版本部署在不同的网络驱动器位置中
- 可以很好地安装每个版本,但是程序运行时会崩溃。
- 运行MSBuild时ApplicationName更改了,我发现在应用程序名称更改为例如的同时,该应用程序仍在寻找原始的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流程:
@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 Studio\2017\Professional\MSBuild\15.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.HOPPE-BMT.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)
at System.Reflection.RuntimeAssembly.nLoad(System.Reflection.AssemblyName,Boolean)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName,Boolean)
at System.Reflection.Assembly.Load(System.Reflection.AssemblyName)
at System.Windows.Navigation.BaseUriHelper.GetLoadedAssembly(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,System.Xaml.XamlObjectWriterSettings,System.Uri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader,System.Xaml.Permissions.XamlAccessLevel,System.Uri)
at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream,System.Windows.Markup.ParserContext,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.HOPPE-BMT.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\c.nowottny\AppData\Local\Apps\2.0\XNQORKVG.2DT\5A4N7BAY.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进行构建时更改了程序集名称,则将找不到引用的文件并导致应用程序崩溃。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。