VS 2017文档级加载项构建因com可见组件而失败

时间:2017-02-20 15:07:08

标签: c# excel vba vsto visual-studio-2017

我安装了VS 2013,并添加了2017 RC 我使用C#进行了一些自定义的文档级修改excel解决方案,这很好用 然后我在电子表格中添加了一些VBA代码,并在this link之后添加了一个com-visible类(如果我尝试在chrome中打开它但在边缘工作正常则会失败)。

在ThisWorkbook.cs中,我有以下代码......

using System.Runtime.InteropServices;

namespace WeekendingTabsNET40
{
    [ComVisible(true)]
    public interface IWeekending
    {
        string DisplayTaggedSheets ();
        string DisplayDates ();
    }

    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    public class QueryWeekending : IWeekending
    {
        private readonly WeekEnding.WeekEnding _we;
        public QueryWeekending ()
        {
            _we = Globals.ThisWorkbook?.WeekEnding;
        }
        string IWeekending.DisplayTaggedSheets ()
        {
            return _we.DisplayTaggedSheets();
        }
        string IWeekending.DisplayDates ()
        {
            return _we.DisplayDates();
        }
    }

    public partial class ThisWorkbook
    {
        public WeekEnding.WeekEnding WeekEnding;

        private void ThisWorkbook_Startup(object sender, System.EventArgs e)
        {
            WeekEnding = new WeekEnding.WeekEnding(this, Globals.Factory);
        }

        private void ThisWorkbook_Shutdown(object sender, System.EventArgs e)
        {
        }

        protected override object GetAutomationObject ()
        {
            return new QueryWeekending();
        }

        #region VSTO Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisWorkbook_Startup);
            this.Shutdown += new System.EventHandler(ThisWorkbook_Shutdown);
        }

        #endregion
    }
}

在我将ReferenceAssemblyFromVbaProject设置为true并构建项目后,我收到以下错误...

  

错误MSB3217:无法注册程序集“obj \ Debug \ WeekendingTabsNET40.dll”。无法加载文件或程序集'Microsoft.VisualStudio.Tools.Office.BuildTasks,Version = 15.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。该系统找不到指定的文件。 (1,1)

enter image description here

这与VS 2017 RC的实例有关 任何人都可以建议问题是什么?

构建输出

Rebuild All started ...
  Build started 21/02/2017 2:26:37 AM.
       1>Project "C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekendingTabsNET40\WeekendingTabsNET40.sln" on node 1 (WeekendingTabsNET40:Rebuild target(s)).
       1>ValidateSolutionConfiguration:
           Building solution configuration "Debug|Any CPU".
       1>Project "C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekendingTabsNET40\WeekendingTabsNET40.sln" (1) is building "C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekendingTabsNET40\WeekendingTabsNET40\WeekendingTabsNET40.csproj" (2) on node 1 (Rebuild target(s)).
       2>Project "C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekendingTabsNET40\WeekendingTabsNET40\WeekendingTabsNET40.csproj" (2) is building "C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekEndingTabs\WeekEnding\WeekEnding.csproj" (3:3) on node 1 (default targets).
       3>GenerateTargetFrameworkMonikerAttribute:
         Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
         CoreCompile:
           C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.CSharp.dll" /link:"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.Excel.dll" /link:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.v4.0.Utilities.dll" /link:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.v4.0.Utilities.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.v4.0.Framework.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.VisualStudio.Tools.Applications.Runtime.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Windows.Forms.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\WeekEnding.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /target:library /utf8output Properties\AssemblyInfo.cs WeekEnding.cs "C:\Users\Admin\AppData\Local\Temp\.NETFramework,Version=v4.5.AssemblyAttributes.cs"
           Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Roslyn
         _CopyFilesMarkedCopyLocal:
           Copying file from "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.v4.0.Utilities.dll" to "bin\Debug\Microsoft.Office.Tools.Common.v4.0.Utilities.dll".
           Copying file from "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.dll" to "bin\Debug\Microsoft.Office.Tools.Excel.dll".
           Copying file from "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.v4.0.Utilities.dll" to "bin\Debug\Microsoft.Office.Tools.Excel.v4.0.Utilities.dll".
           Copying file from "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.v4.0.Framework.dll" to "bin\Debug\Microsoft.Office.Tools.v4.0.Framework.dll".
           Copying file from "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.VisualStudio.Tools.Applications.Runtime.dll" to "bin\Debug\Microsoft.VisualStudio.Tools.Applications.Runtime.dll".
         CopyFilesToOutputDirectory:
           Copying file from "obj\Debug\WeekEnding.dll" to "bin\Debug\WeekEnding.dll".
           WeekEnding -> C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekEndingTabs\WeekEnding\bin\Debug\WeekEnding.dll
           Copying file from "obj\Debug\WeekEnding.pdb" to "bin\Debug\WeekEnding.pdb".
       3>Done Building Project "C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekEndingTabs\WeekEnding\WeekEnding.csproj" (default targets).
       2>CoreResGen:
           "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\resgen.exe" /useSourcePath /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.CSharp.dll" /r:"C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekendingTabsNET40\packages\Microsoft.Office.Interop.Excel.15.0.4795.1000\lib\net20\Microsoft.Office.Interop.Excel.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.v4.0.Utilities.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.v4.0.Utilities.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.VisualStudio.Tools.Applications.Runtime.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Windows.Forms.dll" /r:"C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekEndingTabs\WeekEnding\bin\Debug\WeekEnding.dll" /compile Properties\Resources.resx,obj\Debug\WeekendingTabsNET40.Properties.Resources.resources Sheet1.resx,obj\Debug\WeekendingTabsNET40.Sheet1.resources ThisWorkbook.resx,obj\Debug\WeekendingTabsNET40.QueryWeekending.resources
           Processing resource file "Properties\Resources.resx" into "obj\Debug\WeekendingTabsNET40.Properties.Resources.resources".
           Processing resource file "Sheet1.resx" into "obj\Debug\WeekendingTabsNET40.Sheet1.resources".
           Processing resource file "ThisWorkbook.resx" into "obj\Debug\WeekendingTabsNET40.QueryWeekending.resources".
         GenerateTargetFrameworkMonikerAttribute:
         Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
         CoreCompile:
           C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:x86 /warn:4 /define:VSTO40;DEBUG;TRACE /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.CSharp.dll" /link:"C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekendingTabsNET40\packages\Microsoft.Office.Interop.Excel.15.0.4795.1000\lib\net20\Microsoft.Office.Interop.Excel.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.v4.0.Utilities.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.v4.0.Utilities.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.VisualStudio.Tools.Applications.Runtime.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Windows.Forms.dll" /reference:"C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekEndingTabs\WeekEnding\bin\Debug\WeekEnding.dll" /debug+ /debug:full /optimize- /out:obj\Debug\WeekendingTabsNET40.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /resource:obj\Debug\WeekendingTabsNET40.Properties.Resources.resources /resource:obj\Debug\WeekendingTabsNET40.Sheet1.resources /resource:obj\Debug\WeekendingTabsNET40.QueryWeekending.resources /target:library /utf8output Chart1.cs Chart1.Designer.cs Properties\AssemblyInfo.cs Sheet1.cs Sheet1.Designer.cs Sheet10.cs Sheet10.Designer.cs Sheet11.cs Sheet11.Designer.cs Sheet2.cs Sheet2.Designer.cs Sheet3.cs Sheet3.Designer.cs Sheet4.cs Sheet4.Designer.cs Sheet5.cs Sheet5.Designer.cs Sheet6.cs Sheet6.Designer.cs Sheet7.cs Sheet7.Designer.cs Sheet8.cs Sheet8.Designer.cs Sheet9.cs Sheet9.Designer.cs ThisWorkbook.cs ThisWorkbook.Designer.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs "C:\Users\Admin\AppData\Local\Temp\.NETFramework,Version=v4.5.AssemblyAttributes.cs"
           Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Roslyn
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(628,9): error MSB3217: Cannot register assembly "obj\Debug\WeekendingTabsNET40.dll". Could not load file or assembly 'Microsoft.VisualStudio.Tools.Office.BuildTasks, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 
       2>Done Building Project "C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekendingTabsNET40\WeekendingTabsNET40\WeekendingTabsNET40.csproj" (Rebuild target(s)) -- FAILED.
       1>Done Building Project "C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekendingTabsNET40\WeekendingTabsNET40.sln" (WeekendingTabsNET40:Rebuild target(s)) -- FAILED.

  Build FAILED.

  Time Elapsed 00:00:01.59
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========

错误

  

错误MSB3217无法注册程序集   “OBJ \调试\ WeekendingTabsNET40.dll”。无法加载文件或程序集   'Microsoft.VisualStudio.Tools.Office.BuildTasks,Version = 15.0.0.0,   Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其中一个   依赖。该系统找不到指定的文件。     C:\ Users \ Admin \ Documents \ Visual Studio   2017 \ Projects \ WeekendingTabsNET40 \ WeekendingTabsNET40 \ WeekendingTabsNET40.csproj C:\ Program   文件(x86)\ Microsoft Visual   Studio \ 2017 \ Professional \ MSBuild \ Microsoft \ VisualStudio \ v15.0 \ OfficeTools \ Microsoft.VisualStudio.Tools.Office.targets 628

更新

我能够使用gacutil清除下载缓存中的所有重复项,但它没有任何区别。

似乎问题是我在GAC中没有Microsoft.VisualStudio.Tools.Office.BuildTasks.dll。

我可以在这里看到这个文件......

  

C:\的Windows \ Microsoft.NET \组件\ GAC_MSIL \ Microsoft.VisualStudio.Tools.Office.BuildTasks \ v4.0_12.0.0.0__b03f5f7f11d50a3a   \ Microsoft.VisualStudio.Tools.Office.BuildTasks.dll

但它不在GAC中(C:\ Windows \ assembly \ GAC_MSIL)

所以...我添加了它,但当然是我的版本12.0.0.0,所以我想我需要找到一种方法来下载15.0.0.0版本。

2 个答案:

答案 0 :(得分:0)

我设法解决了这个问题 我的主要问题是了解VS周围的配置侨民。我需要的DLL实际上是

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.BuildTasks.dll

因为我安装了VS 2017 RC,这是版本15的DLL和MSBuild期望找到的版本。
所以,最后,我刚刚打开VS命令提示符(作为管理员)并运行

,将该版本的Microsoft.VisualStudio.Tools.Office.BuildTasks.dll添加到GAC
gacutil /i C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.BuildTasks.dll

因此,除了理解配置摩擦(在msdn docs rubic的立方体中没有真正描述)之外,我只需要意识到需要正确版本的VisualStudio.Tools.Office.BuildTasks.dll在GAC注册。
正如@HansPassant所提到的,VS 2017 RC安装未能解决这个问题。

答案 1 :(得分:-1)

除此之外,我之前没有解决问题。 我再次尝试使用gacutil来注册"Microsoft.VisualStudio.Tools.Office.BuildTasks.dll". 然后使用VS 2017的开发人员命令提示符作为管理员我正确注册了"Microsoft.VisualStudio.Tools.Office.BuildTasks.dll",之后没有更多的问题来构建“ 演练:在Visual C#Project中从VBA调用代码可以正常工作,直到将方法公开给VBA代码 “。在我的电脑中,我在补丁中找到了"Microsoft.VisualStudio.Tools.Office.BuildTasks.dll"

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\PrivateAssemblies\