VS 2017 文档级加载项构建因 com 可见组件而失败
VS 2017 Document-level add-in build fails with com visible components
我安装了 VS 2013 并添加了 2017 RC。
我在 C# 中做了一些自定义的文档级修改 excel 解决方案,这工作正常。
然后我在电子表格中添加了一些 VBA 代码并在 this link 之后添加了一个 com-visible class (如果我尝试在 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 并构建项目后,出现以下错误...
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. (1, 1)
这与 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 Studio17\Professional\MSBuild.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 Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.v4.0.Utilities.dll" /link:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.v4.0.Utilities.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.v4.0.Framework.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\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 Studio17\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 Studio17\Professional\MSBuild.0\Bin\Roslyn
_CopyFilesMarkedCopyLocal:
Copying file from "C:\Program Files (x86)\Microsoft Visual Studio17\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 Studio17\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 Studio17\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 Studio17\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 Studio17\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 Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.v4.0.Utilities.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.v4.0.Utilities.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio17\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 Studio17\Professional\MSBuild.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 Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.v4.0.Utilities.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.v4.0.Utilities.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\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 Studio17\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 Studio17\Professional\MSBuild.0\Bin\Roslyn
C:\Program Files (x86)\Microsoft Visual Studio17\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 ==========
错误
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.
C:\Users\Admin\Documents\Visual Studio
2017\Projects\WeekendingTabsNET40\WeekendingTabsNET40\WeekendingTabsNET40.csproj C:\Program
Files (x86)\Microsoft Visual
Studio17\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\assembly\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 版本。
我设法解决了这个问题。
我的主要问题是理解围绕 VS 的配置散居。我需要的 DLL 实际上在
C:\Program Files (x86)\Microsoft Visual Studio17\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 Studio17\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.BuildTasks.dll
所以,除了了解配置摩擦(在 msdn 文档规则的立方体中没有真正正确描述)之外,我只需要意识到 VisualStudio.Tools.Office.BuildTasks.dll 的正确版本需要在 GAC 中注册.
正如@HansPassant 所提到的,VS 2017 RC 安装未能解决这个问题。
除此之外,我之前也没有解决问题。
我再次尝试使用 gacutil 注册 "Microsoft.VisualStudio.Tools.Office.BuildTasks.dll".
然后以管理员身份使用 VS 2017 的开发人员命令提示符我正确注册了 "Microsoft.VisualStudio.Tools.Office.BuildTasks.dll"
,此后构建“
演练:在 Visual C# 项目中从 VBA 调用代码工作正常,直到步骤将方法公开给 VBA 代码
”。在我的电脑里,我在补丁
中找到了"Microsoft.VisualStudio.Tools.Office.BuildTasks.dll"
C:\Program Files (x86)\Microsoft Visual Studio17\Community\Common7\IDE\PrivateAssemblies\
我安装了 VS 2013 并添加了 2017 RC。
我在 C# 中做了一些自定义的文档级修改 excel 解决方案,这工作正常。
然后我在电子表格中添加了一些 VBA 代码并在 this link 之后添加了一个 com-visible class (如果我尝试在 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 并构建项目后,出现以下错误...
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. (1, 1)
这与 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 Studio17\Professional\MSBuild.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 Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.v4.0.Utilities.dll" /link:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.v4.0.Utilities.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.v4.0.Framework.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\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 Studio17\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 Studio17\Professional\MSBuild.0\Bin\Roslyn
_CopyFilesMarkedCopyLocal:
Copying file from "C:\Program Files (x86)\Microsoft Visual Studio17\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 Studio17\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 Studio17\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 Studio17\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 Studio17\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 Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.v4.0.Utilities.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.v4.0.Utilities.dll" /r:"C:\Program Files (x86)\Microsoft Visual Studio17\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 Studio17\Professional\MSBuild.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 Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Common.v4.0.Utilities.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Office.Tools.Excel.v4.0.Utilities.dll" /reference:"C:\Program Files (x86)\Microsoft Visual Studio17\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 Studio17\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 Studio17\Professional\MSBuild.0\Bin\Roslyn
C:\Program Files (x86)\Microsoft Visual Studio17\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 ==========
错误
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. C:\Users\Admin\Documents\Visual Studio 2017\Projects\WeekendingTabsNET40\WeekendingTabsNET40\WeekendingTabsNET40.csproj C:\Program Files (x86)\Microsoft Visual Studio17\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\assembly\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 版本。
我设法解决了这个问题。
我的主要问题是理解围绕 VS 的配置散居。我需要的 DLL 实际上在
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.BuildTasks.dll
因为我安装了 VS 2017 RC,这是版本 15 DLL 所在的位置,也是 MSBuild 期望找到的那个。
所以,最后,我通过打开 VS 命令提示符(以管理员身份)和 运行
gacutil /i C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.BuildTasks.dll
所以,除了了解配置摩擦(在 msdn 文档规则的立方体中没有真正正确描述)之外,我只需要意识到 VisualStudio.Tools.Office.BuildTasks.dll 的正确版本需要在 GAC 中注册.
正如@HansPassant 所提到的,VS 2017 RC 安装未能解决这个问题。
除此之外,我之前也没有解决问题。
我再次尝试使用 gacutil 注册 "Microsoft.VisualStudio.Tools.Office.BuildTasks.dll".
然后以管理员身份使用 VS 2017 的开发人员命令提示符我正确注册了 "Microsoft.VisualStudio.Tools.Office.BuildTasks.dll"
,此后构建“
演练:在 Visual C# 项目中从 VBA 调用代码工作正常,直到步骤将方法公开给 VBA 代码
”。在我的电脑里,我在补丁
"Microsoft.VisualStudio.Tools.Office.BuildTasks.dll"
C:\Program Files (x86)\Microsoft Visual Studio17\Community\Common7\IDE\PrivateAssemblies\