在 csproj 中标记程序集 CLSCompliant [英] Mark an assembly CLSCompliant in csproj

查看:47
本文介绍了在 csproj 中标记程序集 CLSCompliant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在回复这个问题时解释了如何在 csproj 中设置 InternalsVisibleTo.

In a reply of this question is explained how to set InternalsVisibleTo in csproj.

我认为这也适用于 CLSCompliant:

<ItemGroup>
    <AssemblyAttribute Include="System.CLSCompliant">
      <_Parameter1>true</_Parameter1>
    </AssemblyAttribute>
</ItemGroup>

但不是!MSBuild 抱怨 true 无法从 string 转换为 bool:

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

有没有办法在 _Parameter1 标签内正确写入布尔值?

Is there a way to correctly write a boolean literal inside _Parameter1 tag?

推荐答案

看来有无法在 .csproj 文件中执行此操作.在链接的 GitHub 问题的评论中,多次提出并拒绝了几种解决方案.唯一的解决方案是添加一个空的 csharp 文件并在其中指定程序集属性.

It appears that there is no way to do this within the .csproj file. Several solutions were proposed and rejected numerous times in the comments of the linked GitHub issue. The only solution is to add an empty csharp file and specify the assembly attributes in there.

例如,在 ArbitraryFileName.cs 中:

e.g., in ArbitraryFileName.cs:

using System;
[assembly: CLSCompliant(true)]

您可能应该将此文件命名为 AssemblyInfo.cs,但实际上名称是什么并不重要.

You should probably name this file AssemblyInfo.cs, but it really doesn't matter what the name actually is.

这篇关于在 csproj 中标记程序集 CLSCompliant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆