使用csc时出现奇怪的警告

时间:2018-08-31 12:45:45

标签: c# visual-studio compiler-errors command-prompt

当我使用csc.exe进行编译时,收到一个奇怪的警告:

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'

编译似乎很好,但是什么触发了此警告? LIB变量是什么?

我正在 Developer Command Prompt VS 2017 中运行此程序,当我直接从vanilla命令提示符运行时,一切正常:

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.

winsdk.bat文件中,有多个对UCRT的引用。我认为这些应该包括C运行时库,但是对于版本10.0.17134.0而言,它们不在光盘上。

1 个答案:

答案 0 :(得分:0)

C#编译器(csc)在当前目录,-lib选项中提到的任何路径以及LIB环境变量中查找引用。不幸的是,当您启动Visual Studio命令提示符时,它会运行vcvarsall.bat来设置LIB环境变量,但是C ++链接器也使用该变量来查找库(静态库)。您在问题中提到的文件夹具有C ++库,但没有任何托管代码。我想这是错误的行为。 我确实看到它已在我的机器中设置

LIB variable set