c++azuredllnuspec

how to use azure.storage.file.shares package in native code of c++


I want to use the Azure.storage.file.shares package and its dependent packages in my c++ application. However is try to download the same from nuget package manager, I get error as "Could not install package 'Azure.Storage.File.Share'. You are trying to install this package into a project that targets 'native,Version=v0.0'. However I was able to download it using vcpkg, which gave dll's, libs and headers. is it wise to use them directly in my c++ application?


Solution

  • However when I try to download the same from the Nuget package manager, I get an error as "Could not install package 'Azure.Storage.File.Share'. You are trying to install this package into a project that targets 'native, Version=v0.0'

    The error message you received indicates the target platform for the project, which is set to 'native, Version=v0.0', is incompatible with Azure.Storage.File.Share package. This indicates that native C++ applications aren't supposed to be used with the package and The 'Azure.Storage.Files.Shares' package is primarily intended for .NET applications.

    To use the Azure storage file share library, you need to download the necessary files using vcpkg and you can use them directly in your application.

    To use the library, include the required header files and link to the library files. The code samples included in the documentation provide examples of how to use the library.

    To install the package you can use the below command:

    vcpkg install azure-storage-files-shares-cpp
    

    Which will install and download the packages in your environment.

    After downloading the packages, I tried with the same sample code to create file share which is provided in the official document and it executed successfully.

    Code:

    #include <iostream>
    #include <stdlib.h>
    #include <vector>
    #include <azure/storage/files/shares.hpp>
    
    using namespace Azure::Storage::Files::Shares;
    
    int main()
    {
        std::string shareName = "share1";
        const char* connectionString = "<Your connection string>";
        // Initialize a new instance of ShareClient
        auto shareClient = ShareClient::CreateFromConnectionString(connectionString, shareName);
    
        // Create the files share. This will do nothing if the files share already exists.
        std::cout << "Creating files share: " << shareName << std::endl;
    
        shareClient.CreateIfNotExists();
        
    }
    

    Output:

    Creating files share: share1
    

    Portal: enter image description here

    Reference:

    Quickstart: Azure Storage Files Share library v12 - C++ | Microsoft Learn