In a reply of this question is explained how to set InternalsVisibleTo
in csproj.
I presumed this worked also for CLSCompliant
:
<ItemGroup>
<AssemblyAttribute Include="System.CLSCompliant">
<_Parameter1>true</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
But is not! MSBuild complains that true
can't be converted to from string
to bool
:
> dotnet build
Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 418.35 ms for C:\Users\coder\OneDrive\Projects\pickall\src\PickAll.Sample\PickAll.Sample.csproj.
Restore completed in 418.33 ms for C:\Users\coder\OneDrive\Projects\pickall\src\PickAll.Specs\PickAll.Specs.csproj.
Restore completed in 418.33 ms for C:\Users\coder\OneDrive\Projects\pickall\src\PickAll\PickAll.csproj.
obj\Debug\netstandard2.0\PickAll.AssemblyInfo.cs(14,32): error CS1503: Argument 1: cannot convert from 'string' to 'bool' [C:\Users\coder\OneDrive\Projects\pickall\src\PickAll\PickAll.csproj]
obj\Debug\net461\PickAll.AssemblyInfo.cs(14,32): error CS1503: Argument 1: cannot convert from 'string' to 'bool' [C:\Users\coder\OneDrive\Projects\pickall\src\PickAll\PickAll.csproj]
Build FAILED.
obj\Debug\netstandard2.0\PickAll.AssemblyInfo.cs(14,32): error CS1503: Argument 1: cannot convert from 'string' to 'bool' [C:\Users\coder\OneDrive\Projects\pickall\src\PickAll\PickAll.csproj]
obj\Debug\net461\PickAll.AssemblyInfo.cs(14,32): error CS1503: Argument 1: cannot convert from 'string' to 'bool' [C:\Users\coder\OneDrive\Projects\pickall\src\PickAll\PickAll.csproj]
0 Warning(s)
2 Error(s)
Time Elapsed 00:00:18.37
Is there a way to correctly write a boolean literal inside _Parameter1
tag?
Solution 1
<ItemGroup>
<AssemblyAttribute Include="System.CLSCompliant">
<_Parameter1>true</_Parameter1>
<_Parameter1_TypeName>System.Boolean</_Parameter1_TypeName>
</AssemblyAttribute>
</ItemGroup>
Solution 2
<ItemGroup>
<AssemblyAttribute Include="System.CLSCompliant">
<_Parameter1>true</_Parameter1>
<_Parameter1_IsLiteral>true</_Parameter1_IsLiteral>
</AssemblyAttribute>
</ItemGroup>
Solution 3:
From a comment below by @cremore :
If you write the full class name, so CLSCompliantAttribute
, this now works even without the additional _Parameter1_TypeName
or _Parameter1_IsLiteral
tags.
<ItemGroup>
<AssemblyAttribute Include="System.CLSCompliantAttribute">
<_Parameter1>true</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
Important NOTES:
A pull request (Allow parameter type name to be specified for WriteCodeFragment task) has recently been merged in the MSBuild repository that enables to mark an assembly CLSCompliant in the csproj file exactly as described in your original question.
It should be available soon (May 2021) in version 16.10 preview 3 (not sure if that refers to the MSBuild version or the Visual Studio version). Quoting user Forgind from the mentioned pull request comments:
This should be available in 16.10 preview 3. I will try to remember to ping you in this thread when that's available. That should be roughly a month from now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With