Windows 10无法将文件关联到ClickOnce应用程序

9
我有一个 ClickOnce 应用程序,它在 Windows 7 上运行良好。但是当我在 Windows 10 设备上安装时,似乎无法正确关联我们应用程序的特定文件。
如果我右键单击该文件并选择“打开方式”,我可以在列表中看到“ClickOnce 应用程序部署支持库”。但是,如果我选择此选项,会出现“此应用程序无法在你的 PC 上执行”的消息。如果我直接选择 ClickOnce 应用程序的 .exe 文件(C:\Users\xxx\AppData\Local\Apps...),它也无法正常工作(版本和更新检测)。
我能够安装我的应用程序,并且能够从开始菜单中正确运行它,唯一不起作用的就是文件关联。我尝试过卸载和重新安装,但没有改变什么。
编辑: 我在另一台 Windows 10 设备上安装了该应用程序,一切都正常(包括“自动安装和手动指定时的文件关联”)。因此,我认为问题并不是适用于所有 Windows 10 设备的“通用”问题。
2个回答

2
我能够重现montueron的问题。在开启日志记录(https://msdn.microsoft.com/en-us/library/dd996997.aspx)并设置日志记录位置(https://msdn.microsoft.com/en-us/library/ms404265.aspx)后,我能够确定文件关联被跳过了:“.tiff”文件关联被跳过,因为另一个应用程序正在使用它。
以下是我在Windows 10上解决问题的方法。我的目标是将我的ClickOnce程序“Tif2PDF”与.TIF和.TIFF图像文件相关联。
  1. Create a unique file association in the ClickOnce Publish settings in Visual Studio 2017. I am not using .TIF at this time, we just want to create the appropriate registry entry under HKCU\Software\Classes\Tif2PDF which will get removed in the un-install process.

    Properties->Publish->Options->File Associations.
    extension=.tif2pdf
    description=Tif2PDF
    progID=Tif2PDF
    icon=Resources\Tif2PDF.ico
    
  2. In the Tif2PDF program startup process, we need to add registry settings when it is installed - only run when it is updated:

    if ( System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
                   && ApplicationDeployment.CurrentDeployment.IsFirstRun )
    
    Computer\HKEY_CURRENT_USER\Software\GuardTech\PDFTool\Capabilities\FileAssociations
    .tif="Tif2PDF"    
    .tiff="Tif2PDF"
    
这两个条目告诉Windows使用HKCU\Software\Classes\Tif2PDF 条目来处理 TIF 和 TIFF 文件类型。
  1. Tell Windows this is a registered application. This value points to the key created in step 2.

    Computer\HKEY_CURRENT_USER\Software\RegisteredApplications
    Tif2PDF="Software\Tif2PDF\Capabilities"
    
此时,您应该在Windows资源管理器中的“打开方式”选项中看到一个名为“ClickOnce Application Deployment Support Library”的选项。此时它可以使用,但是让我们添加一个标签和图标。
  1. Create key and values below.

    string iconSourcePath == Path.Combine(System.Windows.Forms.Application.StartupPath, @"Resources\Tif2PDF.ico");
    Computer\HKEY_CURRENT_USER\Software\Classes\Tif2PDF\Application
    ApplicationIcon=iconSourcePath
    ApplicationName="Tif2PDF"
    
  2. You program will need to handle command line arguments a little differently

    //Get the normal command lines arguments in case the EXE is called directly
    List<string> argList = new List<string>(Environment.GetCommandLineArgs());
    argList.RemoveAt(0); //Remove the application.EXE entry
    
    // this is how arguments are passed from windows explorer to clickonce installed apps when files are associated in explorer
    if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments?.ActivationData != null )
    {
    argList.AddRange( AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData);
    }
    
  3. We should try to cleanup these registry settings when we un-install the program by following thedracle's post Custom action on uninstall (clickonce) - in .NET


1
我刚刚使用Visual Studio 2015(< 5分钟)以管理员身份创建了一个测试应用程序(Windows窗体应用程序)。
1)在“属性/发布/选项/文件关联”下添加了以下条目:
扩展名:.abcd
描述:测试
ProgID:2
图标:一个图标文件
2)在“属性/发布”下,我按下“立即发布”并运行安装程序。
3)创建一个文本文件,将其重命名为test.abcd。
它在Windows 10下按预期工作,因此您可以创建一个测试应用程序/验证它是否正常工作,并查看与现有应用程序的区别。32/64位、框架、签名等。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接