22

I want to publish package about sdl_mixer, it's a native package. I did as tutorial said. I put .dll .hand .lib files into package content, but the final package didn't work. So what is right way to create c++ nuget package?

Another question: I found in nuget, most native c++ package are published in two packages, for example:

sdl2_ttf.v140

sdl2_ttf.v140.redist

What is difference between those two files? And how can I publish my packages like that?


Update:

I followed the tutorial on how to publish native packages. I have written the following autopkg file

 

nuget{
    nuspec {
        id = MySdl_mixer;
        version :2.0.0.0;
        title: sdl mixer;
        authors: { Sam Lantinga, Stephane Peter, Ryan Gordon};
        owners: {spartawhy117};
        licenseUrl: "http://libsdl.org/license.php";
        projectUrl: "http://libsdl.org/index.php";
        iconUrl:"";
        requireLicenseAcceptance:false;
        summary:Nothing;
        description: @"SDL_mixer is a sample multi-channel audio mixer library.... 
    ";
       releaseNotes: "Release of C++ ";
       copyright:Copyright 2015;
       tags: {v140 ,sdl_mixer , native, CoApp };
};

    files {
        #defines {
            Include = include\;
            Bin = bin64\;
            Lib = lib64\;
        }

        include:{"${Include}*"};

        [x64,v140,debug,desktop]{
            lib: ${Lib}SDL2_mixer.lib;
            bin: ${Bin}SDL2_mixer.dll;
        }
        [x64,v140,release,desktop]{
            lib: ${Lib}SDL2_mixer.lib;
            bin: ${Bin}SDL2_mixer.dll;
        }
     };
    targets {
            Defines += HAS_SDLMIXER;
     };
}

Running the command Write-NuGetPackage .\sdl_mixer.autopkg returns an error unexpected input of the end. What is the problem here?

6
  • "didn't work" does not tell much... what is the issue? nothing gets installed, runtime errors occur, components are missing? Commented Aug 2, 2016 at 19:11
  • @dlatikay when I want to include the .h file , it remind me can't find the head file . Commented Aug 3, 2016 at 6:49
  • Can you make sure you didn't miss "}" at the end of your autopkg file? The error indicate that the autopkg file content is incorrect. Commented Aug 11, 2016 at 6:56
  • Do you know how to add multiple macros to targets? like Defines += HAS_SDLMIXER;HAS_B Commented Jul 12, 2018 at 22:00
  • For Visual C/C++ Nuget Packages look at my answer stackoverflow.com/questions/38740881/… Commented Nov 18, 2021 at 11:50

3 Answers 3

14

I searched around for days until I found there is really no help out there on the internet at all. I did managed to piece together how to do it, and through trial and error got it working well. Which I have documented here:

https://digitalhouseblog.wordpress.com/2019/08/22/how-to-make-a-nuget-package-for-c/

But I'll summarize here anyways:

  • Gather or stage your native library files into a folder of your choosing.
  • Create a *.nuspec file in that folder.
  • Edit the *.nuspec file to include the files you want to include in your package.
  • Create a *.props file
  • Call nuget pack to create the package.
  • Push the nuget package to a feed somewhere.
  • Create a packages.config file.
  • Edit the visual studio project file to import the *.props file

Notice that the nuget tools inside the visual studio IDE are NEVER used. You have to do a LOT manually. See the link for full details and explanations.

0
0

You can use CoApp PowerShell tools to create the Native Nuget packages easily.

Creating Native Packages

If you’re interested in publishing your native libraries via NuGet, you can choose to create the NuGet packages manually. However, there’s an easier way--the CoApp project volunteered to write C++ oriented tools to create NuGet packages, and they have released a beta version of their tools. These tools simplify the process of generating the MSBuild files and NuGet packages from existing header and library files--you just need to create a configuration script to describe the contents of the package and then run the tools to generate the NuGet package.

Refer to this link for more detailed information: Support for Native Projects.

2
  • 3
    CoApp powershell isn't supported anymore. No support of VS2015 and 2017.
    – Whiletrue
    Commented Nov 7, 2018 at 15:53
  • 1
    That link at docs.nuget.org is worthless. Doesn't explain how to do it all, just that it can be done. Still looking for examples.
    – C.J.
    Commented Aug 21, 2019 at 21:31
0

If you want to do this from Visual Studio C++ using a Visual Studio Solution and projects. Look at my answer here.

Create Nuget package for C++/C Visual Studio Solution projects

The above question seems to be Linux.

2
  • Link-only answers are discouraged here as they low-effort and low-value. If this is a duplicate question, please flag it as such.
    – Chris
    Commented Feb 5, 2021 at 20:51
  • Yes, you are "pointing at an answer", which makes it a link-only answer as I stated in my previous comment. Such answers are discouraged here, and routinely deleted. Please read the link I provided, which says in part, 'When someone goes on Stack Exchange, the question "answer" should actually contain an answer. Not just a bunch of directions towards the answer.'
    – Chris
    Commented Jun 10, 2022 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.