如何在ASP.NET MVC 6和Visual Studio 2015中添加COM引用? [英] How to add COM references in ASP.NET mvc 6 and Visual Studio 2015?
问题描述
我可以在没有问题的Visual Studio 2012中执行此操作,但在2015年使用MVC 6不能执行此操作,图片相关:
I can do that in Visual Studio 2012 w/o problems, but not in 2015 with MVC 6, pic related:
有可能吗?
推荐答案
我发现您的问题很有趣. DotNet应用程序通过互操作程序集对COM的访问权限可以针对 tlbimp.exe .通常,您已经生成了许多这样的输入.您可以在%SystemRoot%\assembly\GAC_MSIL
目录中看到.例如,我在计算机上安装了Office.我将在下面显示如何创建一个小型的ASP.NET 5项目,该项目使用COM界面启动Microsoft Word.
I find your question interesting. DotNet application access to COM via interop assembly which can be generated with respect of tlbimp.exe for example. Typically you have already generated a lot of such intreops. You can see there in %SystemRoot%\assembly\GAC_MSIL
directory. For example I have Office installed on my computer. I will show below how to create small ASP.NET 5 project which starts Microsoft Word using the COM interface.
我创建了简单的控制台应用程序,已从"frameworks"
中删除了"dnxcore50"
部分.然后,我在解决方案资源管理器中选择参考",单击鼠标右键并选择添加参考...".现在,我单击浏览..."按钮
I created simple Console Application, have removed "dnxcore50"
part from "frameworks"
. Then I selected "References" in the Solution Explorer, clicked right mouse and chosen "Add Reference...". Now I clicked "Browse..." button
导航到C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Word\15.0.0.0__71e9bce111e9429c
,选择Microsoft.Office.Interop.Word.dll
,然后单击添加"按钮.之后,我可以在解决方案资源管理器中看到以下视图:
navigated to C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Word\15.0.0.0__71e9bce111e9429c
, chosen Microsoft.Office.Interop.Word.dll
and clicked "Add" button. After that, I could see the following view in Solution explorer:
重要的是要提到,global.json
已被修改,"wrap"
目录已包含在"projects"
部分中. wrap
和lib
文件夹是在解决方案中创建的
It's important to mention, that global.json
was modified and "wrap"
directory was included in "projects"
part. The folders wrap
and lib
was created in the solution
文件夹lib\dnx451
包含Microsoft.Office.Interop.Word.dll
的副本. 其他 project.json
是在wrap\Microsoft.Office.Interop.Word
文件夹中创建的,具有以下内容:
The folder lib\dnx451
contains the copy of Microsoft.Office.Interop.Word.dll
. Additional project.json
was created in wrap\Microsoft.Office.Interop.Word
folder with the following content:
{
"version": "1.0.0-*",
"frameworks": {
"dnx451": {
"bin": {
"assembly": "../../lib/dnx451/Microsoft.Office.Interop.Word.dll"
}
}
}
}
并且主project.json
现在包含
{
"frameworks": {
"dnx451": {
"dependencies": {
"Microsoft.Office.Interop.Word": "1.0.0-*"
}
}
}
}
我创建了启动Microsoft Word并使之可见的简单程序:
I created the simple program which starts Microsoft Word and makes it visible:
namespace OldConsoleAppCom
{
public class Program
{
public static void Main(string[] args)
{
var wordApp = new Microsoft.Office.Interop.Word.Application();
wordApp.Visible = true;
}
}
}
一个人可以编译这样的应用程序并成功运行.
One can compile such application and successfully run.
这篇关于如何在ASP.NET MVC 6和Visual Studio 2015中添加COM引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!