Saturday, February 27, 2010

Sick of these C# warnings? Here's how to eliminate them...

8>warning CS1668: Invalid search path 'c:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\lib\i386' specified in 'LIB environment variable' -- 'The system cannot find the path specified. '

8>warning CS1668: Invalid search path 'C:\Program Files\Microsoft Visual Studio 9.0\lib' specified in 'LIB environment variable' -- 'The system cannot find the path specified. '

The Visual Studio installer does a mysterious thing here.

The entries found at "Tools > Options > Projects and Solutions > VC++ Directories" point to some non-existing directories. But the entries are used to populate the LIB environment variable when building projects inside the IDE. So... if you build a C# project in the IDE, you get this warning about invalid search paths in the LIB environment variable.

Now, I'll give them the benefit of the doubt: maybe some installations of Visual Studio *do* produce these directories. However, this warning has been occurring all through the VS 2005 and 2008 series and I have always encountered it on every machine I've ever built a C# project on. Of course, there's one thing unusual about the way I typically build C# code that I forgot to mention: I usually build C# code with custom commands that drive the C# compiler directly from the build context of a C++ project. So I understand if Microsoft doesn't have a test that tries this scenario out. "Why would anybody do that, anyway?" :-)

The fact remains: those settings cause these warnings, and the installer has never installed those directories for me. I'm calling it a bug.

The way to get rid of this warning is to edit the entries to remove the ones that point to non-existent directories. The trick is figuring out which ones they are.

This one: "c:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\lib\i386" comes from the entry for "Win32" / "Library files":

$(VCInstallDir)atlmfc\lib\i386

VCInstallDir evaluates to "c:\Program Files\Microsoft Visual Studio 9.0\VC\"

This one: "C:\Program Files\Microsoft Visual Studio 9.0\lib" comes from the entry for "Win32" / "Library files":

$(VSInstallDir)lib

VSInstallDir evaluates to "C:\Program Files\Microsoft Visual Studio 9.0\"

Click on each of those in the Tools > Options dialog and delete them.

Voila. Warning gone.

2 comments:

Mchael MchaelD said...

There is nothing like that in tool>options in c#

David said...

You mean in some Visual Studio C# Express Edition? Which version? I was referring mostly to the Visual Studio paid editions. But I could see how they might leave out "C++ specific settings" from a C# Express Edition...

Sorry this post didn't help you out. Perhaps there's another way to fix it for your particular situation. The root cause is probably still the same: non-existent directories listed in the LIB env var. If you figure out where the LIB env var setting comes from for your Visual Studio, you'll probably also figure out how to change it and eliminate the bogus directories.

Good luck!