代码之家  ›  专栏  ›  技术社区  ›  Lasse V. Karlsen

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

  •  21
  • Lasse V. Karlsen  · 技术社区  · 15 年前

    我有两个对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>
    

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

    2 回复  |  直到 15 年前
        1
  •  8
  •   Richard    15 年前

    如果没有用于SQL Lite的“anycpu”程序集,那么您将被困在单独的构建中。

    若要执行单独的生成,请创建一个在条件属性组中提供正确路径的属性,然后使用该属性进行单个引用(即,将条件移动到“引用项”组之外)。有一个使用此类属性的示例(对于自定义FxCop扩展) here ,您可以看到在 .csproj 文件。

    (总结:vs不能处理所有的可能性msbuild可以做到。)

        2
  •  1
  •   Anton Tykhyy    15 年前

    正如我看到的,你最初的项目的问题是 <SpecificVersion>True</SpecificVersion> 指定 System.Data.SQLite, Version=1.0.61.0 ,而实际的程序集是1.0.65版。正在修复程序集名称中的版本 Reference 应该帮忙。