1

When I compile using csc.exe I'm getting a strange warning:

C:\...\>csc HelloWorld.cs /o- /target:exe
Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354)
Copyright (C) Microsoft Corporation. All rights reserved.

warning CS1668: Invalid search path 'C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\ucrt\x86' specified in 'LIB environment variable' -- 'directory does not exist'

The compilation seems to be fine, but what's triggering this warning? What's this LIB variable?

I'm running this in the Developer Command Prompt VS 2017, when I run directly from a vanilla command prompt things are fine:

C:\...\>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe" HelloWorld.cs /target:exe /o+
Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354)
Copyright (C) Microsoft Corporation. All rights reserved.

Looking at the winsdk.bat file there's several references to UCRT. I think these are supposed to be including C runtime libraries, they aren't present on the disc though, for version 10.0.17134.0.

BanksySan
  • 27,362
  • 33
  • 117
  • 216

1 Answers1

1

The C# compiler (csc) looks for references in current directory, any path mentioned in -lib option, and the LIB environment variable. Unfortunately when you start Visual studio command prompt it runs vcvarsall.bat which sets the LIB environment variable, but that is also used by the C++ linker to look for libraries (static ones). The folder you mentioned in the question has C++ libs but not any managed code. I suppose it's a faulty behavior. I do see that it sets in my machine

LIB variable set

Soundararajan
  • 2,000
  • 21
  • 23
  • Where does it run `vcvarsall.bat`? I don't see that? – BanksySan Aug 31 '18 at 18:48
  • (win 8 or later) From start menu -> type "Command Prompt". Choose "Developer command prompt for Visual Studio". Right click "Open File location". It will open a shortcut file. Right click and open the properties of the shortcut file. The command line to start will be something like this one – Soundararajan Sep 01 '18 at 03:44
  • (win 8 or later) From start -> Open "Developer command prompt for Visual Studio". Right click "Open File location". It will open a shortcut file. Open the properties of shortcut. The command line will be %comspec% /k ""C:\...... \VsDevCmd.bat"". Whereas if you try "MSBUild command prompt" from start and do the same it look like %comspec% /k ""C:\....\VsMSBuildCmd.bat"". If you open the batch file in former it will define LIB. The later will not. So opening "Developer command prompt" and running c# should be avoided. Use "MSBuild command prompt" instead. – Soundararajan Sep 01 '18 at 03:54