How to add COM references in ASP.NET mvc 6 and Visual Studio 2015?

℡╲_俬逩灬. 提交于 2019-12-10 09:38:56

问题


I can do that in Visual Studio 2012 w/o problems, but not in 2015 with MVC 6, pic related:

Is it even possible?


回答1:


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.

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

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:

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

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"
      }
    }
  }
}

and the main project.json contains now

{
  "frameworks": {
    "dnx451": {
      "dependencies": {
        "Microsoft.Office.Interop.Word": "1.0.0-*"
      }
    }
  }
}

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.



来源:https://stackoverflow.com/questions/34520838/how-to-add-com-references-in-asp-net-mvc-6-and-visual-studio-2015

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!