.NET项目中的条件引用,有可能摆脱警告吗?

ang*_*son 22 c# conditional reference project 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>
Run Code Online (Sandbox Code Playgroud)

这会产生以下警告:

Warning 1 The referenced component 'System.Data.SQLite' could not be found.     
Run Code Online (Sandbox Code Playgroud)

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

我开发时只考虑将项目配置为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>
Run Code Online (Sandbox Code Playgroud)

然后在我的参考:

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

这摆脱了警告,但这是正确的吗?

Ric*_*ard 9

如果SQL Lite没有"AnyCPU"程序集,则会遇到单独的构建.

要进行单独的构建,请创建一个属性,该属性在条件属性组中提供正确的路径,然后使用该属性具有单个引用(即将条件移动到引用项组之外).有使用这种属性(自定义FxCop的扩展名)的例子在这里,你可以看到很多有条件的性能在开始被定义.csproj文件.

(摘要:VS不能处理MSBuild的所有可能性.)