none
error MSB8020: The build tools for WindowsKernelModeDriver10.0 cannot be found RRS feed

  • Question

  • I got following error building a C++ driver project in the container.

     C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(3
    79,5): error MSB8020: The build tools for WindowsKernelModeDriver10.0 (Platform Toolset = 'WindowsKernelModeDriver10.0') cannot be found. To build using the WindowsKernelModeDriver10.0 build tools, please install WindowsKernelModeDriver10.0 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution".


    How to resolve this error? Thanks.


    Dockerfile for the container

    FROM mcr.microsoft.com/windows/servercore:ltsc2019
    
    ENV TEMP_DIR="c:/temp"
    
    SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
    
    
    # Create temp file for installers
    RUN New-Item -ItemType Directory -Force -Path $env:TEMP_DIR; 
    
    
    # Install VS BuildTools 2019 
    SHELL ["cmd", "/S", "/C" ]
    COPY ./BuildTools2019 "$TEMP_DIR/BuildTools2019"
    RUN C:\temp\BuildTools2019\vs_buildtools_2019.exe --quiet --wait --norestart --nocache --noWeb \
           --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools \
           --add Microsoft.VisualStudio.Workload.VCTools \
           --add Microsoft.Net.Component.3.5.DeveloperTools \
           --add Microsoft.VisualStudio.Component.Windows10SDK.17763 \
           --add Microsoft.VisualStudio.Component.Windows10SDK.18362 \
           --add Microsoft.VisualStudio.Component.VC.CMake.Project \
           --add Microsoft.VisualStudio.Component.VC.ATLMFC
    SHELL ["powershell", "-NoProfile", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; "]
    
    RUN dir "$env:TEMP_DIR" | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
    
    # Install WDK 10 1703
    COPY ./WDK1703 "$TEMP_DIR/WDK1703"
    RUN \
        Start-Process -FilePath "$env:TEMP_DIR/WDK1703/wdksetup.exe" -ArgumentList '/q', '/norestart' -PassThru | Wait-Process;
    
    RUN dir "$env:TEMP_DIR" | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
    
    # Install WDK 10 1809
    COPY ./WDK1809 "$TEMP_DIR/WDK1809"
    RUN \
        Start-Process -FilePath "$env:TEMP_DIR/WDK1809/wdksetup.exe" -ArgumentList '/q', '/norestart' -PassThru | Wait-Process;
    
    RUN dir "$env:TEMP_DIR" | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
    
    # Install WDK 10 1903
    COPY ./WDK1903 "$TEMP_DIR/WDK1903"
    RUN \
        Start-Process -FilePath "$env:TEMP_DIR/WDK1903/wdksetup.exe" -ArgumentList '/q', '/norestart' -PassThru | Wait-Process;
    
    RUN dir "$env:TEMP_DIR" | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
    
    # Install VCRedist 2012 
    COPY ./VCRedist2012 "$TEMP_DIR/VCRedist2012"
    RUN \
       Start-Process -FilePath "$env:TEMP_DIR/VCRedist2012/vcredist_x64_2012.exe" -ArgumentList '/passive', '/norestart' -PassThru | Wait-Process;
    
    
    COPY ./ABC "c:/ABC"
    
    
    



    Tuesday, August 13, 2019 6:24 AM

Answers

  • WDK includes a VSIX package, which contains the Visual Studio extension that integrates Visual C++ with the WDK build .props and .targets.

    You need to install the MSBuild .props and .targets included in the VSIX package. Fortunately, you can manually extract the VSIX and copy the contents into Visual Studio. Assuming your VS Build Tools are installed in C:\BuildTools2019, you can add the following commands to your Dockerfile: 

    # Install WDK.vsix manually by extracting its contents.
    RUN Copy-Item "\"${Env:ProgramFiles(x86)}\Windows Kits\10\Vsix\VS2019\WDK.vsix\"" 'C:\wdkvsix.zip'
    RUN Expand-Archive 'C:\wdkvsix.zip' -DestinationPath 'C:\WdkVsix'
    RUN Copy-Item 'C:\WdkVsix\$MSBuild\Microsoft\*' -Destination 'C:\BuildTools2019\MSBuild\Microsoft' -Recurse -Force
    RUN Remove-Item 'C:\WdkVsix' -Force -Recurse 
    RUN Remove-Item 'C:\wdkvsix.zip' -Force


    Wednesday, August 14, 2019 6:23 PM

All replies

  • WDK includes a VSIX package, which contains the Visual Studio extension that integrates Visual C++ with the WDK build .props and .targets.

    You need to install the MSBuild .props and .targets included in the VSIX package. Fortunately, you can manually extract the VSIX and copy the contents into Visual Studio. Assuming your VS Build Tools are installed in C:\BuildTools2019, you can add the following commands to your Dockerfile: 

    # Install WDK.vsix manually by extracting its contents.
    RUN Copy-Item "\"${Env:ProgramFiles(x86)}\Windows Kits\10\Vsix\VS2019\WDK.vsix\"" 'C:\wdkvsix.zip'
    RUN Expand-Archive 'C:\wdkvsix.zip' -DestinationPath 'C:\WdkVsix'
    RUN Copy-Item 'C:\WdkVsix\$MSBuild\Microsoft\*' -Destination 'C:\BuildTools2019\MSBuild\Microsoft' -Recurse -Force
    RUN Remove-Item 'C:\WdkVsix' -Force -Recurse 
    RUN Remove-Item 'C:\wdkvsix.zip' -Force


    Wednesday, August 14, 2019 6:23 PM
  • Thanks.

    First all there is no WDK.visx file under container directory.

    So I copied WDK.visx from my Win 10 system.

    Here is the code change made for dockerfile.

    COPY ./WDKvsix "C:/WDKvsix"
    
    RUN Copy-Item 'C:\WDKvsix\$MSBuild\Microsoft\*' -Destination 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft' -Recurse -Force

    And the manually installed VSIX package does not resolve the problem, I got a new error:

    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\Platforms\x64\PlatformToolsets
    \WindowsKernelModeDriver10.0\Toolset.targets(24,3): error MSB4019: The imported project "C:\Program Files (x86)\Windows
     Kits\10\build\WindowsDriver.common.targets" was not found. Confirm that the path in the <Import> declaration is correc
    t, and that the file exists on disk.

    BTW, when I using the build Tools 2017, there is no need to install VSIX package, and the C++ driver projects can be compiled without problem, why we need to do this for build Tools 2019?




    Thursday, August 15, 2019 3:07 AM
  • It sounds like the WDK wasn't installed correctly if you say that you couldn't find the VSIX file, nor MsBuild cannot find WindowsDriver.Common.targets.

    First, check that the file "C:\Program Files (x86)\Windows Kits\10\build\WindowsDriver.Common.targets" exists indeed in your container. If it doesn't, then it means there was a problem with your WDK installation. I'd review the logs at "%TEMP%\wdk" in the container to try to find what went wrong.

    Also, I'm not sure what's the reason you didn't hit the error with BuildTools 2017, as it should had required the VSIX installed, too. The files provided by the package are required in order for VS to be able to find the required WDK MsBuild files for building driver projects.

    Friday, August 16, 2019 6:08 PM