2

I am compiling a simple hello world .NET Core (net5.0-windows) app with MSBuild.exe.

Every time I build, I get the following warnings:

CSC : warning CS1668: Invalid search path 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\ATLMFC\lib\x64' specified in 'LIB environment variable' -- 'directory does not exist' [<snipped>\build\<snipped>\HelloWorld.csproj]
CSC : warning CS1668: Invalid search path 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\lib\x64' specified in 'LIB environment variable' -- 'directory does not exist' [<snipped>\build\<snipped>\HelloWorld.csproj]

Why am I getting these warnings and how can I resolve them? There are no other warnings or errors, and the compiled executable runs fine.

This is the default Windows Forms App created through Visual Studio 2019:

enter image description here

I am then running MSBuild.exe from git bash in the project directory.

I found this question, but I don't know how to "look carefully in your LIB path", as the answer suggests. I didn't set that variable, I'm guessing csc did.

MHebes
  • 2,290
  • 1
  • 16
  • 29

1 Answers1

1

All this error is saying is that you're missing a directory. Since the error occurs twice, you're missing two directories.

These are the directories:

'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\ATLMFC\lib\x64'
'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\lib\x64'

The error also says that the existence of these directories is checked because they're specified in 'LIB environment variable'.

To quote Microsoft, "Environment variables store data that's used by the operating system and other programs. For example, the WINDIR environment variable contains the location of the Windows installation directory. Programs can query the value of this variable to determine where Windows operating system files are located."

In this case, the LIB environment variable stores directories to check for libraries when building applications. When building your application, MSBuild passes the directories in LIB to the C# compiler (CSC), and CSC checking each one for libraries to use. Two of those directories, it turns out, don't exist on your particular computer, so CSC shows this error.

To fix this problem, you can just remove the directories from your LIB environment variable.

To do this, open the environment variable editor. You can do this by either searching for 'system env' in your Windows 10 start menu, selecting the "Edit the system environment variables" result and then clicking the "Environment Variables" button at the bottom of the window that appears, or by running the following in an Administrator command prompt:

rundll32 sysdm.cpl,EditEnvironmentVariables

In the window that appears you'll see two sections. The top section is labelled User variables for <your username> and the bottom section is labelled System variables. Look through each section for a LIB environment variable. Open each LIB environment variable for editing by clicking it and then clicking the 'Edit...' button associated with that section. Each time you'll be presented a list of directories. Find the directory entries that are showing up in your build errors and delete them. If you have two LIB variables, both directories will probably only be in one of the two.

You might be wondering why this issue appeared in the first place. It's possible that you deleted these directories when you modified your Visual Studio 2019 installation, but for whatever reason, the Visual Studio installer didn't clean up the LIB environment variable. Perhaps because you modified it in the past. Perhaps because the installer just missed it.

EchoLynx
  • 410
  • 5
  • 11
  • 1
    I'm also seeing this error with a fresh install of MSBuild 2022. I seems like the MSBuild installer has a bug which results in the `atlmfc\lib\x64` directory being added to the LIB environment variable although this directory hasn't been created. For now I'm simply silencing this warning by installing ATLMFC eventhough I technically don't need it. – Martin Konrad Mar 03 '23 at 09:36