zeromq / clrzmq4

ZeroMQ C# namespace (.NET and mono, Windows, Linux and MacOSX, x86 and amd64)
GNU Lesser General Public License v3.0
241 stars 112 forks source link

Make use of nuget, msbuild and .target file #52

Closed goldenbull closed 8 years ago

goldenbull commented 8 years ago

It's not necessary for C# project to include amd64 and i386 folders. Instead we can use a .target file to automatically copy the needed folders and files into the output target folder. This is a built-in ability of MsBuild.

My simple xz(lzma) wrapper project on GitHub may be a sample: https://github.com/goldenbull/ManagedXZ/blob/master/ManagedXZ/build/ManagedXZ.targets

gillima commented 8 years ago

This was exactly what i tried with this PR: https://github.com/zeromq/clrzmq4/pull/50

metadings commented 8 years ago

Well, yes... And no... You changed my nuspec file :-) You also made a .target file referencing the nuget directory, however the MSBuild should also work without nuget, which is my main concern...

You may PR this one again, but please use

<None Include="$(MSBuildThisFileDirectory)amd64/libzmq.so">

or the like, instead of a relative reference like $(MSBuildThisFileDirectory)../../lib/net40....

I can't test this right now because I don't have a Windows machine, so you need to make this PR carefully :-)

Don't forget to do a git pull before your PR! Please also try to do nuget pack ... I recently changed \ to /, because I'm running nuget on mono/Linux, and I don't know if running nuget on .NET/Windows does "get" the files. (nuget on mono/Linux didn't get them, throwing an exeption that there were no files referenced. I wonder if we need a ZeroMQ.mono.nuspec and a ZeroMQ.vs.nuspec.)

gillima commented 8 years ago

Hmm... i did the change mainly for this reason: Normally we do not add dll, so, dylib or similar files to your project GIT repositories. Also the nuget packages are excluded by .gitignore. Before we build the project, nuget restore is downloading them.

As you might know, nuget restore doesn't add the content file (again) to the projects and so the build fails. Using references to the package folder would fix this issue.

With adding the files as content and then use a custom build target, it would be possible to set the allways copy property for the files, but the nuget restore problem would persist.

Do you see any chance to fix both, the allways copy and the nuget restore issue on both, Windows and Linux?

goldenbull commented 8 years ago

@metadings it's obvious that at the beginning of a project, user must download the DLLs using nuget. If user hopes to run msbuild without nuget afterwards, it's his responsibility to add the packages folder into git. And nuget also has a local cache which prevents the unnecessary downloading action.

metadings commented 8 years ago

No. You can download the release .zip which contains a prebuild bin\Release folder. You may also use nuget - it's just your "responsibility" to set the files to copy if newer - or copy the files.

Now there may be people using MSBuild, with and without nuget - you just need to copy these files. Don't you want to make a new .target file @gillima ?

goldenbull commented 8 years ago

@metadings yes you are right, prebuild .zip files is another possible way. For these people using MSBuild without nuget, they will add the DLLs into project manually or edit the Post-Build script in project settings. Both are independent of the nuget spec config.

metadings commented 8 years ago

I'm in favor of the following ZeroMQ.target file.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <None Include="$(MSBuildThisFileDirectory)amd64\libzmq.so">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Include="$(MSBuildThisFileDirectory)amd64\libzmq.dll">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Include="$(MSBuildThisFileDirectory)amd64\libsodium.so">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Include="$(MSBuildThisFileDirectory)amd64\libsodium.dll">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Include="$(MSBuildThisFileDirectory)i386\libzmq.so">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Include="$(MSBuildThisFileDirectory)i386\libzmq.dll">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Include="$(MSBuildThisFileDirectory)i386\libsodium.so">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Include="$(MSBuildThisFileDirectory)i386\libsodium.dll">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
    </ItemGroup>
</Project>

Would you like to test this one, first with nuget, second just with MSBuild? I can't do so, because I don't have a Windows machine right now.

@gillima - do I also need ... ?

    <file src="ZeroMQ.targets" target="build/net40/ZeroMQ.targets" />
goldenbull commented 8 years ago

I will try to make nuget work better with .targets file. Does clrzmq4 supports net40 only for the moment?

gillima commented 8 years ago

@metadings Yes you need to add the ZeroMQ.targets added to the build directory. This will tell nuget to add the custom build target to your project when you install the nuget. The name of the target has to be the same as the id or the package. See: nuspec

metadings commented 8 years ago

@goldenbull Yes, I don't had the time/the Windows computer to make the project libzmq v3 or .NET v2.0/v3.0 or v3.5 (backwards-)compatible - it would be possible, but I see no reason for being too old, even WinXP runs .NET4.

@gillima Would you like to make your PR again? Don't forget to do a git pull first.

goldenbull commented 8 years ago

34 is the same issue.

goldenbull commented 8 years ago

I created PR #53 and then found @gillima has a better way to copy files, so I created #54 to overwrite #53 . Both have the same output which is what I need.

metadings commented 8 years ago

Please have a look on the new ZeroMQ v4.1.0.19 package on nuget.org.

Is this package now good, in Visual Studio?

goldenbull commented 8 years ago

4.1.0.19 works fine in Visual Studio 2015. Good job! :+1:

metadings commented 8 years ago

:+1:

gillima commented 8 years ago

Great job! Works with VS2013 and fixes nuget restore issues. Thanks!

Limro commented 8 years ago

Works like a charm. Good job!