.NET 项目中的条件引用,可以摆脱警告吗? [英] Conditional references in .NET project, possible to get rid of warning?

查看:40
本文介绍了.NET 项目中的条件引用,可以摆脱警告吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have two references to a SQLite assembly, one for 32-bit and one for 64-bit, which looks like this (this is a test project to try to get rid of the warning, don't get hung up on the paths):

<Reference Condition=" '$(Platform)' == 'x64' " Include="System.Data.SQLite, Version=1.0.61.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64">
  <SpecificVersion>True</SpecificVersion>
  <HintPath>....LVK LibrariesSQLite3version_1.0.65.064-bitSystem.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 LibrariesSQLite3version_1.0.65.032-bitSystem.Data.SQLite.DLL</HintPath>
</Reference>

这会产生以下警告:

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

我可以摆脱这个警告吗?

Is it possible for me to get rid of this warning?

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

One way I've looked at it to just configure my project to be 32-bit when I develop, and let the build machine fix the reference when building for 64-bit, but this seems a bit awkward and probably prone to errors.

还有其他选择吗?

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

The reason I want to get rid of it is that the warning is apparently being picked up by TeamCity and periodically flagged as something I need to look into, so I'd like to get completely rid of it.

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

Edit: Per the answer, I tried this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    ...
    <SqlitePath>....LVK LibrariesSQLite3version_1.0.65.032-bit</SqlitePath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    ...
    <SqlitePath>....LVK LibrariesSQLite3version_1.0.65.032-bit</SqlitePath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    ...
    <SqlitePath>....LVK LibrariesSQLite3version_1.0.65.064-bit</SqlitePath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    ...
    <SqlitePath>....LVK LibrariesSQLite3version_1.0.65.064-bit</SqlitePath>
</PropertyGroup>

然后在我的参考中:

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

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

This got rid of the warning, but is it correct?

推荐答案

如果没有适用于 SQL Lite 的AnyCPU"程序集,您将无法使用单独的构建.

If there is no "AnyCPU" assembly for SQL Lite you are stuck with separate builds.

要进行单独的构建,请在条件属性组中创建一个提供正确路径的属性,然后使用该属性来拥有单个引用(即将条件移到引用项组之外).有一个使用此类属性的示例(用于自定义 FXCop 扩展)here,你可以看到在 <代码>.csproj 文件.

To do separate builds create a property that gives the correct path in a conditional property group and then use that property to have a single reference (i.e. move the conditional outside the references items group). There is an example of using such a property (for a custom FXCop extension) here, you can see lots of conditional properties being defined at the start of the .csproj file.

(总结:VS 无法处理 MSBuild 的所有可能性.)

(Summary: VS doesn't handle all of the possibilities MSBuild does.)

这篇关于.NET 项目中的条件引用,可以摆脱警告吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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