flutter-permission-handler icon indicating copy to clipboard operation
flutter-permission-handler copied to clipboard

Nuget not Found and CMake Error

Open rayliverified opened this issue 2 years ago • 26 comments

🐛 Bug Report

Building Permissions Handler on Windows fails due to 2 errors.

  1. Nuget not installed
  2. Failed to run cppwinrt.exe

CC @azchohfi

Expected behavior

Building for Windows works.

Nuget.exe not found, trying to download or use cached version.
Argument cannot be null or empty
Parameter name: primarySources
CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:29 (message):
Failed to install nuget package Microsoft.Windows.CppWinRT.2.0.210806.1


Exception: Unable to generate build files

Reproduction steps

  1. If Nuget is not added to the PATH, Nuget not installed error occurs.
  2. Run a project with permission_handler on Windows.
Launching lib\main.dart on Windows in debug mode...
Building Windows application...
CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:38 (message):
  Failed to run cppwinrt.exe


Exception: Unable to generate build files

rayliverified avatar Mar 24 '22 19:03 rayliverified

This has nothing to do with the download of nuget.exe or the fact that it is not on the PATH. This message is expected if nuget.exe is not on the PATH, but it is only informative, not an error. Nuget.exe is being downloaded and is being executed. The problem seems to be that the "nuget.exe install" command is failing. Seems like a misconfiguration in your Visual Studio, which sets the default nuget sources. Could you please send a screenshot of the NuGet Package Manager tab on VS's Options? It should have the nuget.org option, poiting to the nuget v3.

azchohfi avatar Mar 25 '22 18:03 azchohfi

Thank you for taking a look Alexandre

snap_screen_20220325132730

rayliverified avatar Mar 25 '22 18:03 rayliverified

Do you have multiple installations of VS? This is really weird, and I don't know exactly what is happening. Does it work if you do have nuget.exe on your path?

azchohfi avatar Mar 25 '22 18:03 azchohfi

Unfortunately not, I've added nuget to my path. The installation error disappears but the second error persists.

I did have VS 2019 installed before upgrading to VS 2022 a few weeks ago. But during this testing, I've only had 1 VS installed.

rayliverified avatar Mar 25 '22 20:03 rayliverified

I can't reproduce this, so I don't know what is happening. Can you try to run the full command from the command line? nuget.exe install Microsoft.Windows.CppWinRT -Version 2.0.210806.1 -OutputDirectory packages This should be executed from the build folder, so something like: your_project\build\windows If this command succeeds, then the build process should work. If not, we can probably at least get some more info into why this is happening.

azchohfi avatar Mar 25 '22 20:03 azchohfi

snap_screen_20220325154407

rayliverified avatar Mar 25 '22 20:03 rayliverified

Succeeds but builds still fail with:

CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:38 (message):
  Failed to run cppwinrt.exe


Exception: Unable to generate build files

rayliverified avatar Mar 25 '22 20:03 rayliverified

What happens if you run the cppwinrt command? ./packages/Microsoft.Windows.CppWinRT.2.0.210806.1/bin/cppwinrt.exe -input sdk -output include

Maybe this is a missing SDK?

azchohfi avatar Mar 25 '22 21:03 azchohfi

Hmmm, am I supposed to see anything happen? The cppwinrt.exe file is there. When I run the command, there's no output but it seems to succeed.

rayliverified avatar Mar 25 '22 21:03 rayliverified

This is what is weird then. There might be some issue with your VS's cmake, or something else, since this: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler_windows/windows/CMakeLists.txt#L34-L38 Is also not running fine, as you mentioned that it failed. I honestly don't know what is happening with your box. Can you try to replicate this in a different machine?

azchohfi avatar Mar 25 '22 21:03 azchohfi

No worries! Let's wait and see if anyone else has this issue. I ran this on another computer and it failed as well.

rayliverified avatar Mar 25 '22 22:03 rayliverified

Facing the same image

GauravCalidig avatar Mar 26 '22 07:03 GauravCalidig

I have the same issue. Only in windows mode. If I remove permission_handler from pubspec.yaml, it runs ok. Until last Friday, it was ok.

afonseca69 avatar Mar 29 '22 17:03 afonseca69

Facing the same image

The screenshot you sent is not an issue, just a "warning". It can be safely ignored. Are you having the same other issue when building? If you run the ./packages/Microsoft.Windows.CppWinRT.2.0.210806.1/bin/cppwinrt.exe -input sdk -output include command, does it succeed?

azchohfi avatar Mar 29 '22 17:03 azchohfi

Same error here before updating Visual Studio: Nuget.exe not found, trying to download or use cached version. CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:29 (message): Failed to install nuget package Microsoft.Windows.CppWinRT.2.0.210806.1

After updating Visual Studio Installer and Visual Studio 2019 the error was gone. The warning (first line) still appears but the application compiles.

jmolins avatar Apr 02 '22 11:04 jmolins

same issue, when i ran flutter run -d windows or flutter build windows ,it never finished. i am using vs 2022 image

guchengxi1994 avatar Apr 25 '22 05:04 guchengxi1994

Same error here before reinstall Visual Studio 2022.

At first,i am using vs 2022 1.Nuget is not added to the PATH,build failed with Nuget.exe not found, trying to download or use cached version.; 2.Nuget is added to the PATH,build failed with CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:38 (message): Failed to run cppwinrt.exe; 3.reinstall vs 2019 the same problem; 4.reinstall vs 2022 the same problem; 5.install vs 2022 after uninstall vs and use VisualStudioUninstaller,build successed;

I hope this may help you.

Misutesu avatar Apr 25 '22 06:04 Misutesu

Same error here before reinstall Visual Studio 2022.

At first,i am using vs 2022 1.Nuget is not added to the PATH,build failed with Nuget.exe not found, trying to download or use cached version.; 2.Nuget is added to the PATH,build failed with CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:38 (message): Failed to run cppwinrt.exe; 3.reinstall vs 2019 the same problem; 4.reinstall vs 2022 the same problem; 5.install vs 2022 after uninstall vs and use VisualStudioUninstaller,build successed;

I hope this may help you.

I had the same problem again today after I executed flutter clean.

But this time the error message is more detailed,Maybe it's because I have http_proxy|https_proxy configured in path. The following is the error message.

Nuget.exe not found, trying to download or use cached version.
  Performing download step (download and verify) for 'nuget-populate'
  -- verifying file...
         file='G:/Develop/Flutter-Project/map_demo/build/windows/_deps/nuget-subbuild/nuget-populate-prefix/src/nuget.exe'
  -- SHA256 hash of
      G:/Develop/Flutter-Project/map_demo/build/windows/_deps/nuget-subbuild/nuget-populate-prefix/src/nuget.exe
    does not match expected value
      expected: '04eb6c4fe4213907e2773e1be1bbbd730e9a655a3c9c58387ce8d4a714a5b9e1'
        actual: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
  -- File already exists but hash mismatch. Removing...
  -- Downloading...
     dst='G:/Develop/Flutter-Project/map_demo/build/windows/_deps/nuget-subbuild/nuget-populate-prefix/src/nuget.exe'
     timeout='none'
     inactivity timeout='none'
  -- Using src='https://dist.nuget.org/win-x86-commandline/v6.0.0/nuget.exe'
  CMake Error at nuget-subbuild/nuget-populate-prefix/src/nuget-populate-stamp/download-nuget-populate.cmake:170 (message):
    Each download failed!

CUSTOMBUILD : error : downloading 'https://dist.nuget.org/win-x86-commandline/v6.0.0/nuget.exe' failed [G:\Develop\Flutter-Project\map_demo\build\windows\_deps\nuget-subbuild\nuget-populate.vcxproj]
            status_code: 4
            status_string: "A requested feature, protocol or option was not found built-in in this libcurl due to a build-time decision."
            log:
            --- LOG BEGIN ---
            Uses proxy env variable no_proxy == 'localhost,127.0.0.1,::1'

    Uses proxy env variable https_proxy == 'https://127.0.0.1:7891'

    Unsupported proxy 'https://127.0.0.1:7891', libcurl is built without the
    HTTPS-proxy support.

    Closing connection -1



            --- LOG END ---

Misutesu avatar Apr 26 '22 08:04 Misutesu

I removed this package and related codes when build on windows and add them on mobiles now ...

guchengxi1994 avatar Apr 26 '22 14:04 guchengxi1994

set no_proxy var !

au-top avatar May 03 '22 14:05 au-top

I download a nuget.exe file and add it to PATH , it can build apps now.

guchengxi1994 avatar May 09 '22 08:05 guchengxi1994

Fixed after downloading Nuget.exe manually and adding it to the PATH

XuanTung95 avatar May 21 '22 13:05 XuanTung95

For me helped manual downloading of nuget like in comment https://github.com/Baseflow/flutter-permission-handler/issues/819#issuecomment-1120819084, then adding the https://api.nuget.org/v3/index.json into NuGet sources through UI on Visual Studio Settings (like at screenshot at https://github.com/Baseflow/flutter-permission-handler/issues/819#issuecomment-1079291883) and then manual running command from https://github.com/Baseflow/flutter-permission-handler/issues/819#issuecomment-1079419482... May be i'v a little overkill...

Nashev avatar Jun 03 '22 11:06 Nashev

This randomly started happening to me today; didn't change anything. Very strange.

ollyde avatar Jun 03 '22 13:06 ollyde

Adding to the path manually didn't help But this is just an annoying error. As far as I can see it doesn't interfere at all.

EwertonDutra avatar Jul 11 '22 14:07 EwertonDutra

Sometimes this happens to me, sometimes it doesn't. When it does happen, sometimes it recovers, sometimes it crashes out.

JaffaKetchup avatar Jul 19 '22 12:07 JaffaKetchup

I also had the problem building windows desktop. Updated VS2019, added nuget.exe to path, added nuget.org to VS sources, still compile error. Uninstalled VS2019, Installed VS2022 using VS Installer & C++ workloads. Compiles fine.

jcollier7 avatar Dec 06 '22 05:12 jcollier7

I also needed to delete the windows directory in my project and had to run flutter create . again. After that all was fine.

otizhi avatar Dec 30 '22 20:12 otizhi

what happend?

➜ nuget.exe install Microsoft.Windows.CppWinRT -Version 2.0.210806.1 -OutputDirectory packages
Feeds used:

Argument cannot be null or empty
参数名: primarySources

lucasjinreal avatar Apr 10 '23 02:04 lucasjinreal

This is usually caused by an configuration error regarding NuGet package manager. The permission_handler_windows package makes use of NuGet to download the Microsoft.Windows.CppWinRT library which contains is used to generate C++ header files to access the Windows native runtime SDK, needed to communicate with the GPS hardware.

I am not really sure what causes the configuration error, however here are some steps that can be verified:

  1. Make sure the default NuGet configuration file exists at the following path %appdata%\NuGet\NuGet.Config. If it doesn't exists create it with the following contents:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>
  1. If the default NuGet.Config exists with the appropriate content, verify if you are allowed to connect to the https://api.nuget.org/v3/index.json url. Some organisations are configured behind a firewall or proxy blocking access.
  2. Make sure Visual Studio 2022 (not Visual Studio Code) is installed correctly with the "Desktop development with C++" workload including all default options.

If this all fails please run flutter build windows -v. The -v switch will provide verbose information and will give more feedback on why NuGet wasn't able to install the Microsoft.Windows.CppWinRT library.

mvanbeusekom avatar Aug 10 '23 13:08 mvanbeusekom