How to use Office from Visual Studio C#?

前端 未结 4 1029
栀梦
栀梦 2021-02-08 01:21

The technique for adding a reference to the COM interop of Office in Visual Studio is to go to:

  1. References
  2. Add Reference
  3. Select the COM
4条回答
  •  醉梦人生
    2021-02-08 02:02

    An old thread, and probably most people would be happy with CopyLocal=True, however here's another way.. Use both (or more..? thinking Office 2010 if the problem still exists..) references in your project files, and either ignore or just tell MSBuild to ignore the "MSB3284" warning (Library not found). So include this in your .csproj file:

    
       {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}
       2
       3
       0
       primary
       False
    
    

    Followed by:

    
       {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}
       2
       4
       0
       primary
       False
    
    

    I would be interested to see if Microsoft provides a NuGet library for this - just to get everyone on to the same approach. I think that would remove the necessity for people to search the web for these answers... I believe this would be against Microsoft Office's license so they are the only ones to supply it.

    BTW with copy local you have to be careful not to redistribute these library by mistake.

提交回复
热议问题