Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional references in .NET project, possible to get rid of warning?

Tags:

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 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> 

This produces the following warning:

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

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

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.

Any other options?

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 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> 

and then in my reference:

<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?

like image 796
Lasse V. Karlsen Avatar asked Apr 06 '10 09:04

Lasse V. Karlsen


People also ask

How do I fix broken references in Visual Studio?

To fix a broken project reference by correcting the reference path. In Solution Explorer, right-click your project node, and then select Properties. The Project Designer appears. If you're using Visual Basic, select the References page, and then click the Reference Paths button.

What is a Solution in dot net?

Solutions are the containers for all your work in VS.NET. A solution contains a project for each build output. (For example, if you want to build a DLL, an EXE, and an MSI Installer file, your solution will contain three projects.) Projects themselves contain source files.


2 Answers

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

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.

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

like image 136
Richard Avatar answered Dec 05 '22 15:12

Richard


As I see it, the problem with your original project was that you had <SpecificVersion>True</SpecificVersion> specifying System.Data.SQLite, Version=1.0.61.0, whereas the actual assembly was version 1.0.65. Fixing version in the assembly name in Reference ought to help.

like image 26
Anton Tykhyy Avatar answered Dec 05 '22 16:12

Anton Tykhyy