CsprojToVs2017 icon indicating copy to clipboard operation
CsprojToVs2017 copied to clipboard

Work out how to deal with ComVisible and if it can be moved to csproj

Open mungojam opened this issue 5 years ago • 4 comments

It would be good if this could be cleared out or moved to the csproj. Below is a very typical example based on the default project created by Visual Studio. I think without ComVisible(false), the default in the compiler is true.

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("29644e8e-6ee0-4337-8658-c926dfa83f55")]

mungojam avatar Aug 21 '18 19:08 mungojam

Yeah, ComVisible is still true by default in CPS I'm afraid. It's a known bad practice and even VS sets it to false by default in AssemblyInfo on project generation. I believe we must preserve default behavior (true), but make a diagnostic for that case.

andrew-boyarshin avatar Aug 22 '18 14:08 andrew-boyarshin

At least

[assembly: Guid("29644e8e-6ee0-4337-8658-c926dfa83f55")]

could be dropped?

leotsarev avatar Feb 01 '19 12:02 leotsarev

A related issue: https://github.com/Microsoft/msbuild/issues/2281

Perhaps after some time the following code will become available:

<ItemGroup>
  <AssemblyAttribute Include="System.Runtime.InteropServices.ComVisibleAttribute">
    <_Parameter1>false</_Parameter1>
    <_Treat_Parameter1AsLiteral>true</_Treat_Parameter1AsLiteral>
  </AssemblyAttribute>
</ItemGroup>

HavenDV avatar Dec 20 '19 01:12 HavenDV

@HavenDV ... I hope so. I'm still championing my proposed more succinct flavor of:

<ItemGroup>
  <AssemblyAttribute
    Include="System.Runtime.InteropServices.ComVisibleAttribute"
    IsLiteral="true"
    _Parameter1="false" />
</ItemGroup>

.. but I'll take a win however I can get it

commonsensesoftware avatar May 15 '20 20:05 commonsensesoftware