Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Framework.NuGet.Packager to Enhance PopulateFolder() Method to Support Architecture & Platform #84

Open
indomitableMan opened this issue Apr 5, 2018 · 3 comments

Comments

@indomitableMan
Copy link

indomitableMan commented Apr 5, 2018

The PopulateFolder() method in packager.cs currently only supports the use of the <Framework> attribute, however NuGet packages can also support multiple processor architectures (e.g. 'x86' and 'x64') and platforms (e.g.'win81').

So if a user were to specify:

<LibraryFiles Include="..\dir\myLibrary.dll">
<Architecture>x86</Architecture>
<Framework>net40</Framework>
<Platform>win</Platform>
</LibraryFiles>

The PopulateFolder() method would test for the presence of the <Architecture> and <Platform> tags before testing for the presence of the <Framework> tag, and if found, would populate the folders like this: .\runtimes\{platform}-{architecture}\lib\{framework}

For example:
.\runtimes
____\win-x86
________\lib
____________\net40
________________\myLibrary.dll
____________\net45
________________\myLibrary.dll

____ \win-x64
________\lib
____________\net40
________________\myLibrary.dll
____________\net45
________________\myLibrary.dll

More information on this syntax is here: Supporting multiple .NET framework versions

@indomitableMan
Copy link
Author

indomitableMan commented Apr 5, 2018

A modified foreach loop similar to this would work:

        foreach (var item in items)
        {
            var architecture = item.GetMetadata("architecture");
            var framework = item.GetMetadata("framework");
            var platform = item.GetMetadata("platform");
            if (!string.IsNullOrWhiteSpace(platform))
            {
                if (!string.IsNullOrWhiteSpace(architecture))
                {
                    runtime = Path.Combine(libDirectory.FullName, "runtime");
                    if (!Directory.Exists(runtime))
                    {
                        Directory.CreateDirectory(runtime);
                    }
                    platformWithArch = string.Concat(platform, "-", architecture);
                    fullPlatformAndArch = path.Combine(runtime, fullPlatformAndArch);
                    if (!Directory.Exists(fullPlatformAndArch))
                    {
                        Directory.CreateDirectory(fullPlatformAndArch);
                    }
                    if (!string.IsNullOrWhiteSpace(framework))
                    {
                        framework = Path.Combine(fullPlatformAndArch, framework);
                        if (!Directory.Exists(framework))
                        {
                            Directory.CreateDirectory(framework);
                        }

                        File.Copy(item.ItemSpec, Path.Combine(framework, Path.GetFileName(item.ItemSpec)));
                    }
                    else
                    {
                        File.Copy(item.ItemSpec, Path.Combine(fullPlatformAndArch, Path.GetFileName(item.ItemSpec)));
                    }
                }
            }
            if (!string.IsNullOrWhiteSpace(framework))
            {
                framework = Path.Combine(libDirectory.FullName, framework);
                if (!Directory.Exists(framework))
                {
                    Directory.CreateDirectory(framework);
                }

                File.Copy(item.ItemSpec, Path.Combine(framework, Path.GetFileName(item.ItemSpec)));
            }
            else
            {
                File.Copy(item.ItemSpec, Path.Combine(libDirectory.FullName, Path.GetFileName(item.ItemSpec)));
            }
        }

@mikefourie-zz
Copy link
Owner

Hi, please submit a pull request.

@blorger
Copy link

blorger commented Mar 25, 2019

Is it really a good idea to package development dependency for every possible target platform?
I've repackaged NuGet package as neutral (removed net35 folders and moved content of net40 folders one level up). Such package can now be used on any project, native and .NET. At least in Visual Studio 2015.

Why does NuGet package contain binaries for .NET 3.5? Is it to support some older version of Visual Studio? In such case it may be better to provide separate NuGet packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants