你如何分配一个Excel VSTO安装大会位置? [英] How do you assign the Assembly Location of an Excel VSTO Installation?

查看:503
本文介绍了你如何分配一个Excel VSTO安装大会位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建C#编写的文档级工作簿/模板,并使用VSTO安装部署代码。安装项目后我有电子表格的全部功能。不过,当我保存或者安装的表复制到其他路径安装文件夹我碰到下面的错误外:

I'm creating a Document-Level Workbook/Template written in C# and using a VSTO Installer to deploy the code. After installing the project I have full functionality of the Spreadsheet however, when I save or copy the installed sheet to another path outside the installation folder I get the following error:

< IMG SRC =htt​​p://i.stack.imgur.com/bgpvg.pngALT =呃哦!>

通过以​​下的全部细节:

With the following full details:

Name: 
From: file:///C:/Users/Kronos/Desktop/ExcelTemplate1.vsto

************** Exception Text **************
System.Deployment.Application.DeploymentDownloadException: Downloading file:///C:/Users/Kronos/Desktop/ExcelTemplate1.vsto did not succeed. ---> System.Net.WebException: Could not find file 'C:\Users\Kronos\Desktop\ExcelTemplate1.vsto'. ---> System.Net.WebException: Could not find file 'C:\Users\Kronos\Desktop\ExcelTemplate1.vsto'. ---> System.IO.FileNotFoundException: Could not find file 'C:\Users\Kronos\Desktop\ExcelTemplate1.vsto'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
   at System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async)
   at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
   --- End of inner exception stack trace ---
   at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
   at System.Net.FileWebRequest.GetResponseCallback(Object state)
   --- End of inner exception stack trace ---
   at System.Net.FileWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.FileWebRequest.GetResponse()
   at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.GetManifests(TimeSpan timeout)
   at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()

我意识到,这是由于该为 .VSTO 名为.manifest &安培; .DLL 文件不被正确引用为Excel电子表格不再驻留在安装路径。后做一些研究我可以手动改变复制解决这个问题/保存擅长 custom.xml 的.xlsx 从这个文件中的文件:

I realize that this is due the to .VSTO, .manifest & .DLL files not being properly referenced as the Excel spreadsheet no longer resides in the installed path. After doing some research I can manually fix this by changing the copied/saved Excels custom.xml file within the .xlsx file from this:

name="_AssemblyLocation"><vt:lpwstr>ExcelTemplate1.vsto|ca022788-e7c0-41d8-b8ae-2c0ba9edbbf8|vstolocal

要这样:

name="_AssemblyLocation"><vt:lpwstr>file://c:/<path to install dir>/ExcelTemplate1.vsto|ca022788-e7c0-41d8-b8ae-2c0ba9edbbf8|vstolocal

由于这是不是我的客户一个可行的解决方案,我怎么使用或者C#代码,或使上面的变化(最好)的?安装

As this isn't a viable solution for my customers, how do I make the above changes using either C# code, or (more preferably) the installer?

注:我已经尝试创建一个自定义安装行动(的per这个MSDN教程),其中以下设置为 CustomActionData

Note: I've tried creating a Custom Install Action (per this MSDN Tutorial) where the following is set for CustomActionData:

/assemblyLocation="[TARGETDIR]ExcelWorkbookProject.dll"/deploymentManifestLocation="[TARGETDIR]ExcelWorkbookProject.vsto"/documentLocation="[TARGETDIR]ExcelWorkbookProject.xlsx"

无济于事。

推荐答案

您需要遵循 MSDN列出的说明文章您参考,只是多了几分。然而,这是一个有点混乱,没有在文章中的错误。希望这将有助于澄清:

You need to follow the instructions outlined in the MSDN article you referenced, just a little more. However this is a little bit confusing and there is an error in the article. Hopefully this will help clarify:

在文章还有就是你可以下载包含项目的文件例。从那里,你可以参考你的自定义操作针对CS项目的输出。创建一个新的项目,该项目是一个CS类库,具体如下用户脚本复制到您解决问题:

Within the article there is a file that you can download that contains the project example. From there you can reference your Custom Actions against the output of that cs project. Create a new project that is a CS Class Library, copy the following user script specific to solving YOUR issue:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using Microsoft.VisualStudio.Tools.Applications;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using System.IO;
using System.Windows.Forms;

namespace AddCustomizationCustomAction
{
    [RunInstaller(true)]
    public partial class AddCustomization : System.Configuration.Install.Installer
    {
        //Note: you'll have to get the Guid from your specific project in order for it to work.  The MSDN article show you how.
        static readonly Guid SolutionID = new Guid("20cb4d1d-3d14-43c9-93a8-7ebf98f50da5");

        public override void Install(IDictionary stateSaver)
        {
            string[] nonpublicCachedDataMembers = null;


            // Use the following for debugging during the install
            //string parameters = "Parameters in Context.Paramters:";
            //foreach (DictionaryEntry parameter in Context.Parameters)
            //{
            //    parameters = parameters + "\n" + parameter.Key + ":" + parameter.Value;
            //}

            //MessageBox.Show(parameters);

            //MessageBox.Show("total items in parameters: " + Context.Parameters.Count);
            //MessageBox.Show("Document Manifest Location:" + Context.Parameters["deploymentManifestLocation"]);

            Uri deploymentManifestLocation = null;
            if (Uri.TryCreate(
                Context.Parameters["deploymentManifestLocation"],
                UriKind.RelativeOrAbsolute,
                out deploymentManifestLocation) == false)
            {
                throw new InstallException(
                    "The location of the deployment manifest " +
                    "is missing or invalid.");
            }
            string documentLocation =
                Context.Parameters["documentLocation"];
            if (String.IsNullOrEmpty(documentLocation))
            {
                throw new InstallException(
                    "The location of the document is missing.");
            }
            string assemblyLocation =
                Context.Parameters["assemblyLocation"];
            if (String.IsNullOrEmpty(assemblyLocation))
            {
                throw new InstallException(
                    "The location of the assembly is missing.");
            }

            // use the following for debugging
            MessageBox.Show(documentLocation);

            if (ServerDocument.IsCustomized(documentLocation))
            {
                ServerDocument.RemoveCustomization(documentLocation);
            }
            ServerDocument.AddCustomization(
                documentLocation,
                assemblyLocation,
                SolutionID,
                deploymentManifestLocation,
                false,
                out nonpublicCachedDataMembers);
            stateSaver.Add("documentlocation", documentLocation);
            base.Install(stateSaver);
        }

        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
        }

        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);
        }

        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
        }

    }
}

这覆盖安装安装程序的手续。在 base.Install(stateSaver)调用代码的其余部分继续正常的安装。

This overrides the install procedure of the installer. The base.Install(stateSaver) calls the rest of the code to continue the installation as normal.

文章说要用于 CustomActionData 安装自定义操作的以下内容:

The article says to use the following for the CustomActionData of the Install Custom Action:

/assemblyLocation="[TARGETDIR]<YourProjectName>.dll"/deploymentManifestLocation="[TARGETDIR]<YourProjectName>.vsto"/documentLocation="[TARGETDIR]<YourProjectName>.xltx"

然而,它应该是这个(注意PARAMS之间的空格):

However it should be this (note the spaces between params):

/assemblyLocation="[TARGETDIR]<YourProjectName>.dll" /deploymentManifestLocation="[TARGETDIR]<YourProjectName>.vsto" /documentLocation="[TARGETDIR]<YourProejctName>.xltx"

这应该解决您的问题,但要确保它的指向发布,而不是调试重建你的安装程序之前重建的发布版本的任何更改您的Excel项目。

This should solve your issues, however make sure to rebuild any changes to your Excel Project to the release build before rebuilding your installer as it's pointed to the release and not the debug.

这篇关于你如何分配一个Excel VSTO安装大会位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆