Skip to content

NativeAot publish fail #81584

Closed
dotnet/docs
#33870

Description

@Varorbc

Description

ConsoleApp1 -> E:\ConsoleApp1\bin\Release\net7.0\win-x64\ConsoleApp1.dll
系统找不到指定的文件。
Generating native code
文件名、目录名或卷标语法不正确。
C:\Program Files\dotnet\sdk\7.0.102\Sdks\Microsoft.DotNet.ILCompiler\build\Microsoft.NETCore.Native.targets(350,5): err
or MSB3073: 命令“"系统找不到指定的文件。;d:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32213\bin\Hostx64
\x64\link.exe" @"obj\Release\net7.0\win-x64\native\link.rsp"”已退出,代码为 123。 [E:\ConsoleApp1\ConsoleApp1
.csproj]

Reproduction Steps

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
  </PropertyGroup>

</Project>

dotnet publish -r win-x64 -c Release

Expected behavior

publish success

Actual behavior

publish fail

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. ghost added
    untriaged
    on Feb 3, 2023
  2. am11 commented on Feb 3, 2023

    @am11
    Member

    Looks like your Visual Studio installation is in unusual state. Please show the output of:

    :: windows command prompt
    
    "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * ^
        -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ^
        -version [16^,18^) ^
        -property installationPath
  3. added
    needs-author-action
    on Feb 4, 2023
  4. Varorbc commented on Feb 6, 2023

    @Varorbc
    ContributorAuthor
  5. ghost added
    needs-further-triage
    on Feb 6, 2023
  6. ghost removed
    needs-author-action
    on Feb 6, 2023
  7. am11 commented on Feb 6, 2023

    @am11
    Member

    It is the same value as your error message. So it is trying to find Hostx64 directory under that path at d:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32213\bin\Hostx64 which does not exist.

    Check the output of:

    dir d:\Program Files\Microsoft Visual Studio\2022\Preview
    :: does it exist?
    :: do you see VC directory in the output of dir command?

    If it does not, you can try uninstalling Visual Studio and reinstalling again. Otherwise, see microsoft/vswhere#258, microsoft/vswhere#41 and some other discussions to find out the problem with your VS installation (most likely some registry key or environment variable is out of sync).

  8. Varorbc commented on Feb 6, 2023

    @Varorbc
    ContributorAuthor

    image
    image
    image

  9. am11 commented on Feb 6, 2023

    @am11
    Member

    OK. The paths exist. Does it give some useful information if you run the linker command manually?

    cd E:\ConsoleApp1
    
    rmdir /s /q obj
    rmdir /s /q bin
    
    :: let it fail once
    dotnet publish -r win-x64 -c Release -v:diag > publish-dump.log
    
    findstr /I "_FindVCVarsallOutput" publish-dump.log
    findstr /I "_VCVarsAllFound" publish-dump.log
    
    "d:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32213\bin\Hostx64\x64\link.exe" ^
        @"obj\Release\net7.0\win-x64\native\link.rsp"
    
    echo %errorlevel% 
  10. Varorbc commented on Feb 6, 2023

    @Varorbc
    ContributorAuthor

    image

  11. am11 commented on Feb 6, 2023

    @am11
    Member

    Thanks. So 1181 with cannot open input file 'advapi32.lib' looks like dotnet/runtimelab#1449.

    Does this error go away if you unset LIB and LIBPATH environment variables? Like this:

    cd E:\ConsoleApp1
    
    rmdir /s /q obj
    rmdir /s /q bin
    
    echo %LIB%
    set LIB=
    
    echo %LIBPATH%
    set LIBPATH=
    
    dotnet publish -r win-x64 -c Release
    
    "d:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32213\bin\Hostx64\x64\link.exe" ^
        @"obj\Release\net7.0\win-x64\native\link.rsp"
    
    echo %errorlevel% 
  12. Varorbc commented on Feb 6, 2023

    @Varorbc
    ContributorAuthor

    image

  13. 3 remaining items

  14. am11 commented on Feb 6, 2023

    @am11
    Member

    Yes, please test if installing just Windows SDK fixes your problem. If it does, we should (at least) add a note for it explicitly in the documentation that Windows SDK is needed https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/#prerequisites.

    The documentation mentions Desktop development with C++ which may select it automatically in the installer UI, but then in Individual Components tab, user can un-select items. In my Windows 10 system, I selected Desktop development with C++ (and few other things like .NET Framework for my work), but if I remember it correctly, that was enough to get dotnet publish -p:PublishAot=true working.

  15. Varorbc commented on Feb 6, 2023

    @Varorbc
    ContributorAuthor

    Windows SDK installed and work well

  16. Varorbc commented on Feb 6, 2023

    @Varorbc
    ContributorAuthor

    It would be nice to add another check like this

    <Error Condition="'$(_VCVarsAllFound)' == '1'" Text="Platform linker not found. To fix this problem, download and install Visual Studio 2022 from http://visualstudio.com. Make sure to install the Desktop Development for C++ workload. For ARM64 development also install C++ ARM64 build tools." />

  17. am11 commented on Feb 6, 2023

    @am11
    Member

    Yes, or the accompanying bat file (which runs vswhere command) can also detect it and produce the error? Lets see. I will wait for @jkotas thoughts on Windows SDK requirement.

    We switched to vswhere in dotnet/corert@9e2f015. At that time, I had a system which I was restoring to factory settings to create different kinds of undesired states to form error message. IIRC, Windows SDK requirement wasn't spotted; which could be an oversight or because it is now pulled from cryptography lib object required by one of the runtime libs object. Maybe there is a way to not depend on Windows SDK and still facilitate advapi32.lib dependency. 🤔

  18. jkotas commented on Feb 6, 2023

    @jkotas
    Member

    I will wait for @jkotas thoughts on Windows SDK requirement.

    Yes, Windows SDK (and number of other components that come with Desktop development with C++ workload) are required. We do not want to be in a business of reshipping or recreating Windows SDK or other parts of Visual Studio.

    We depend on number of Windows SDK libs, it is not just advapi32.lib:

    <SdkNativeLibrary Include="advapi32.lib" />
    <SdkNativeLibrary Include="bcrypt.lib" />
    <SdkNativeLibrary Include="crypt32.lib" />
    <SdkNativeLibrary Include="iphlpapi.lib" />
    <SdkNativeLibrary Include="kernel32.lib" />
    <SdkNativeLibrary Include="mswsock.lib" />
    <SdkNativeLibrary Include="ncrypt.lib" />
    <SdkNativeLibrary Include="normaliz.lib" />
    <SdkNativeLibrary Include="ntdll.lib" />
    <SdkNativeLibrary Include="ole32.lib" />
    <SdkNativeLibrary Include="oleaut32.lib" />
    <SdkNativeLibrary Include="secur32.lib" />
    <SdkNativeLibrary Include="user32.lib" />
    <SdkNativeLibrary Include="version.lib" />
    <SdkNativeLibrary Include="ws2_32.lib" />

  19. ghost removed
    untriaged
    on Feb 8, 2023
  20. Varorbc commented on Feb 8, 2023

    @Varorbc
    ContributorAuthor

    It would be nice to add another check like this

    <Error Condition="'$(_VCVarsAllFound)' == '1'" Text="Platform linker not found. To fix this problem, download and install Visual Studio 2022 from http://visualstudio.com. Make sure to install the Desktop Development for C++ workload. For ARM64 development also install C++ ARM64 build tools." />

    @jkotas ????

  21. jkotas commented on Feb 9, 2023

    @jkotas
    Member

    I do not mind improving the error handling if it is reasonably simple. However, it is close to impossible to make these script detect all possible ways that your Visual Studio installation can be corrupted.

  22. Varorbc commented on Feb 9, 2023

    @Varorbc
    ContributorAuthor

    At least should detect whether Windows SDK is installed.

  23. agocke commented on Feb 10, 2023

    @agocke
    Member

    It's not clear to me how to detect that. Although if there is an easy way to do so, happy to include it. Maybe we could check the registry inside the build task, assuming there's a well-known registry key.

  24. am11 commented on Feb 10, 2023

    @am11
    Member

    Finding Windows SDK paths manually in all kinds of 32/64 x64/x86/arm64/arm variations robustly gets complex and it is nondeterministic; Windows / VS teams can and do make breaking changes. Even if we figure it out via registry, it doesn't really help because we don't know if the final cl.exe call will actually select the Windows SDK version which we identified as installed, because user can have side-by-side VS installed; one with required components and the other without.

    We can continue using vswhere and add the additional required component ID. This way, it will match the components in context of instance of VS. The problem there is that the current version of vswhere which ships with Visual Studio is 3.0. This version doesn't support glob patterns, so it's not feasible to list all the applicable/supported SDKs IDs. In the next version 3.1.1, they have added glob pattern support which we can use to determine if any Windows SDK version is present that applies to the instance of VS. So for the upcoming VS version, we can improve it a little bit.

    The general guidance is to refer to documentation for prerequisites applicable to your platform. We have similar blind spots in clang/gcc toolchains. For advanced issues, build diagnostics (bin logs or diag logs) help finding the compiler command and troubleshooting.

  25. ghost locked as resolved and limited conversation to collaborators on Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-NativeAOT-coreclrneeds-further-triageos-windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions