From 35b64d5ada9ab2f1ef8919d16cc587ae1d2597b2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 5 Nov 2016 15:05:47 +0100 Subject: [PATCH] contrib/buildsystems: make 'Restore NuGet Packages' work in Visual Studio Visual Studio has this very neat feature that you can get dependencies in the form of NuGet packages, and even further: you can specify in a project what NuGet packages it needs. These dependencies can then be fetched via right-clicking the solution in the Solution Explorer and clicking the "Restore NuGet Packages" entry. This feature is so neat, in fact, that we want to support it in Git for Windows. The idea is that we will be able to provide developers with a checkout of the Git sources that can be built outside of the Git for Windows SDK, using *only* Visual Studio. Signed-off-by: Johannes Schindelin --- contrib/buildsystems/Generators/Vcxproj.pm | 56 ++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/contrib/buildsystems/Generators/Vcxproj.pm b/contrib/buildsystems/Generators/Vcxproj.pm index 67418ed607..bcbb71410b 100644 --- a/contrib/buildsystems/Generators/Vcxproj.pm +++ b/contrib/buildsystems/Generators/Vcxproj.pm @@ -92,7 +92,7 @@ sub createProject { my ($name, $git_dir, $out_dir, $rel_dir, $build_structure, $static_library) = @_; my $label = $static_library ? "lib" : "app"; my $prefix = $static_library ? "LIBS_" : "APPS_"; - my $config_type = $static_library ? "StaticLibrary" : "Utility"; + my $config_type = $static_library ? "StaticLibrary" : "Application"; print "Generate $name vcxproj $label project\n"; my $cdup = $name; $cdup =~ s/[^\/]+/../g; @@ -129,7 +129,7 @@ sub createProject { my $libs = ''; if (!$static_library) { - $libs = join(";", sort(grep /^(?!libgit\.lib|xdiff\/lib\.lib)/, @{$$build_structure{"$prefix${name}_LIBS"}})); + $libs = join(";", sort(grep /^(?!libgit\.lib|xdiff\/lib\.lib|vcs-svn\/lib\.lib|libcurl\.lib|libeay32\.lib|libiconv\.lib|ssleay32\.lib|zlib\.lib)/, @{$$build_structure{"$prefix${name}_LIBS"}})); } $defines =~ s/-D//g; @@ -139,6 +139,39 @@ sub createProject { $defines =~ s/\'//g; die "Could not create the directory $target for $label project!\n" unless (-d "$target" || mkdir "$target"); + + use File::Copy; + copy("$git_dir/compat/vcbuild/packages.config", "$target/packages.config"); + + my $needsCurl = grep(/libcurl.lib/, @{$$build_structure{"$prefix${name}_LIBS"}}); + my $targetsImport = ''; + my $targetsErrors = ''; + my $afterTargets = ''; + open F, "<$git_dir/compat/vcbuild/packages.config"; + while () { + if (/"; + } elsif ($needsCurl && $1 eq 'curl') { + # libcurl is only available targeting v100 and v110 + $libs .= ";$rel_dir\\compat\\vcbuild\\GEN.PKGS\\$1.$2\\build\\native\\lib\\v110\\\$(Platform)\\Release\\dynamic\\libcurl.lib"; + $afterTargets .= "\n "; + } elsif ($needsCurl && $1 eq 'expat') { + # libexpat is only available targeting v100 and v110 + $libs .= ";$rel_dir\\compat\\vcbuild\\GEN.PKGS\\$1.$2\\build\\native\\lib\\v110\\\$(Platform)\\Release\\dynamic\\utf8\\libexpat.lib"; + } + next if ($1 =~ /^(zlib$|openssl(?!.*(x64|x86)$))/); + my $targetsFile = "$rel_dir\\compat\\vcbuild\\GEN.PKGS\\$1.$2\\build\\native\\$1.targets"; + $targetsImport .= "\n "; + $targetsErrors .= "\n "; + } + } + close F; + open F, ">$vcxproj" or die "Could not open $vcxproj for writing!\n"; binmode F, ":crlf :utf8"; print F chr(0xFEFF); @@ -211,6 +244,7 @@ sub createProject { $libs;\$(AdditionalDependencies) + invalidcontinue.obj %(AdditionalOptions) $cdup\\compat\\win32\\git.manifest Console @@ -284,9 +318,25 @@ EOM EOM } print F << "EOM"; + + + - + $targetsImport + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + $targetsErrors + +EOM + if (!$static_library && $afterTargets ne '') { + print F << "EOM"; + $afterTargets + +EOM + } + print F << "EOM"; EOM close F;