c# - .NET 项目中的条件引用是否可以消除警告?

标签 c# reference project conditional compiler-warnings

我有两个对 SQLite 程序集的引用,一个用于 32 位,一个用于 64 位,它看起来像这样(这是一个试图摆脱警告的测试项目,不要挂断路径):

<Reference Condition=" '$(Platform)' == 'x64' " Include="System.Data.SQLite, Version=1.0.61.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64">
  <SpecificVersion>True</SpecificVersion>
  <HintPath>..\..\LVK Libraries\SQLite3\version_1.0.65.0\64-bit\System.Data.SQLite.DLL</HintPath>
</Reference>
<Reference Condition=" '$(Platform)' == 'x86' " Include="System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
  <SpecificVersion>True</SpecificVersion>
  <HintPath>..\..\LVK Libraries\SQLite3\version_1.0.65.0\32-bit\System.Data.SQLite.DLL</HintPath>
</Reference>

这会产生以下警告:

Warning 1 The referenced component 'System.Data.SQLite' could not be found.     

我有可能摆脱这个警告吗?

我看过的一种方法是在开发时将我的项目配置为 32 位,并让构建机器在构建 64 位时修复引用,但这似乎有点尴尬并且可能容易出错错误。

还有其他选择吗?

我想摆脱它的原因是警告显然被 TeamCity 接收并定期标记为我需要调查的内容,所以我想完全摆脱它。


编辑:根据答案,我试过这个:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    ...
    <SqlitePath>..\..\LVK Libraries\SQLite3\version_1.0.65.0\32-bit</SqlitePath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    ...
    <SqlitePath>..\..\LVK Libraries\SQLite3\version_1.0.65.0\32-bit</SqlitePath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    ...
    <SqlitePath>..\..\LVK Libraries\SQLite3\version_1.0.65.0\64-bit</SqlitePath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    ...
    <SqlitePath>..\..\LVK Libraries\SQLite3\version_1.0.65.0\64-bit</SqlitePath>
</PropertyGroup>

然后在我的引用中:

<Reference Include="System.Data.SQLite">
    <SpecificVersion>False</SpecificVersion>
    <HintPath>$(SqlitePath)\System.Data.SQLite.DLL</HintPath>
</Reference>

这消除了警告,但它是否正确?

最佳答案

如果没有适用于 SQL Lite 的“AnyCPU”程序集,您将不得不使用单独的构建。

要进行单独的构建,请创建一个属性,该属性在条件属性组中提供正确的路径,然后使用该属性来获得单个引用(即将条件移动到引用项组之外)。有一个使用此类属性的示例(用于自定义 FXCop 扩展)here ,您可以看到在 .csproj 文件的开头定义了许多条件属性。

(总结:VS 不处理 MSBuild 处理的所有可能性。)

关于c# - .NET 项目中的条件引用是否可以消除警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2583732/

相关文章:

eclipse - Eclipse 中的项目共享

C# - 计算多个文件的总统计数据

c# - 在 ListView 中显示数据库中的多列

ajax - Microsoft.Ajax.Utilities dll : Missing Assembly, 从哪里下载?

rust - 获取对 Vec 元素的可变引用或创建新元素并获取该引用

jenkins - 带有逗号v的cvs文件名

Java Servlet 和其他项目引用

c# - 使用 C# 更改 html5 音频元素的 src 路径

c# - 如何获取显示图像的 (x, y) 坐标?

rust - 为什么解构借用的枚举需要取消引用其字段?