diff --git a/modules/vstudio/tests/vc2010/test_ensure_nuget_imports.lua b/modules/vstudio/tests/vc2010/test_ensure_nuget_imports.lua index 3fdff0a53e..de006fe4bf 100644 --- a/modules/vstudio/tests/vc2010/test_ensure_nuget_imports.lua +++ b/modules/vstudio/tests/vc2010/test_ensure_nuget_imports.lua @@ -44,7 +44,7 @@ if _OPTIONS["test-all"] then function suite.structureIsCorrect() - nuget { "boost:1.59.0-b1", "sdl2.v140:2.0.3", "sdl2.v140.redist:2.0.3" } + nuget { "boost:1.59.0-b1", "sdl2.v140:2.0.3", "sdl2.v140.redist:2.0.3", "WinPixEventRuntime:1.0.220810001", "Microsoft.Direct3D.D3D12:1.608.2" } prepare() test.capture [[ @@ -54,6 +54,9 @@ if _OPTIONS["test-all"] then + + + ]] end diff --git a/modules/vstudio/tests/vc2010/test_extension_settings.lua b/modules/vstudio/tests/vc2010/test_extension_settings.lua index e52120c00a..7e93fcbaf1 100644 --- a/modules/vstudio/tests/vc2010/test_extension_settings.lua +++ b/modules/vstudio/tests/vc2010/test_extension_settings.lua @@ -28,6 +28,22 @@ vc2010.importExtensionSettings(prj) end +-- +-- Writes entries only for nuget packages with props files. +-- + +if _OPTIONS["test-all"] then + function suite.importOnlyNugetPackagesWithProps() + nuget { "boost:1.59.0-b1", "sdl2.v140:2.0.3", "sdl2.v140.redist:2.0.3", "WinPixEventRuntime:1.0.220810001", "Microsoft.Direct3D.D3D12:1.608.2" } + prepare() + test.capture [[ + + + + ]] + end +end + -- -- Writes an empty element when no custom rules are specified. diff --git a/modules/vstudio/tests/vc2010/test_extension_targets.lua b/modules/vstudio/tests/vc2010/test_extension_targets.lua index f205e00e95..d33b52d451 100644 --- a/modules/vstudio/tests/vc2010/test_extension_targets.lua +++ b/modules/vstudio/tests/vc2010/test_extension_targets.lua @@ -65,13 +65,15 @@ if _OPTIONS["test-all"] then function suite.addsImport_onEachNuGetPackage() - nuget { "boost:1.59.0-b1", "sdl2.v140:2.0.3", "sdl2.v140.redist:2.0.3" } + nuget { "boost:1.59.0-b1", "sdl2.v140:2.0.3", "sdl2.v140.redist:2.0.3", "WinPixEventRuntime:1.0.220810001", "Microsoft.Direct3D.D3D12:1.608.2" } prepare() test.capture [[ + + ]] end diff --git a/modules/vstudio/tests/vc2010/test_nuget_packages_config.lua b/modules/vstudio/tests/vc2010/test_nuget_packages_config.lua index 623c67e4b7..89e08852f6 100644 --- a/modules/vstudio/tests/vc2010/test_nuget_packages_config.lua +++ b/modules/vstudio/tests/vc2010/test_nuget_packages_config.lua @@ -44,7 +44,7 @@ -- function suite.structureIsCorrect() - nuget { "boost:1.59.0-b1", "sdl2.v140:2.0.3", "sdl2.v140.redist:2.0.3" } + nuget { "boost:1.59.0-b1", "sdl2.v140:2.0.3", "sdl2.v140.redist:2.0.3", "WinPixEventRuntime:1.0.220810001", "Microsoft.Direct3D.D3D12:1.608.2" } prepare() test.capture [[ @@ -52,6 +52,8 @@ + + ]] end diff --git a/modules/vstudio/vs2010_nuget.lua b/modules/vstudio/vs2010_nuget.lua index 1faeeab5ad..2dcc2eda52 100644 --- a/modules/vstudio/vs2010_nuget.lua +++ b/modules/vstudio/vs2010_nuget.lua @@ -94,32 +94,31 @@ return end - if p.project.isdotnet(prj) then - -- Using the local file listing for "packageEntries" might - -- not exactly match what we would get from the API but this - -- doesn't matter. At the moment of writing, we're only - -- interested in knowing what DLL files the package - -- contains. + -- Using the local file listing for "packageEntries" might + -- not exactly match what we would get from the API but this + -- doesn't matter. At the moment of writing, we're only + -- interested in knowing what DLL files the package + -- contains. - packageAPIInfo.packageEntries = {} + packageAPIInfo.packageEntries = {} - for _, file in ipairs(os.matchfiles(path.translate(path.join(versionPath, "**")))) do - local extension = path.getextension(file) + for _, file in ipairs(os.matchfiles(path.translate(path.join(versionPath, "**")))) do + local extension = path.getextension(file) - if extension ~= ".nupkg" and extension ~= ".sha512" then - table.insert(packageAPIInfo.packageEntries, path.translate(path.getrelative(versionPath, file))) - end + if extension ~= ".nupkg" and extension ~= ".sha512" then + table.insert(packageAPIInfo.packageEntries, path.translate(path.getrelative(versionPath, file))) end + end - if #packageAPIInfo.packageEntries == 0 then - return - end + if #packageAPIInfo.packageEntries == 0 then + return + end - if nuspec:match("(.+)") then - p.warn("NuGet package '%s' may depend on .NET Framework assemblies - package dependencies are currently unimplemented", id) - end + if nuspec:match("(.+)") then + p.warn("NuGet package '%s' may depend on .NET Framework assemblies - package dependencies are currently unimplemented", id) end + if nuspec:match("(.+)") then p.warn("NuGet package '%s' may depend on other packages - package dependencies are currently unimplemented", id) end @@ -283,33 +282,30 @@ packageAPIInfo.verbatimVersion = response.verbatimVersion packageAPIInfo.version = response.version - -- C++ packages don't have this, but C# packages have a -- packageEntries field that lists all the files in the -- package. We need to look at this to figure out what -- DLLs to reference in the project file. - if prj.language == "C#" and not response.packageEntries then + if not response.packageEntries then p.error("NuGet package '%s' version '%s' has no file listing. This package might be too old to be using this API or it might be a C++ package instead of a .NET Framework package.", id, response.version) end - if prj.language == "C#" then - packageAPIInfo.packageEntries = {} - - for _, item in ipairs(response.packageEntries) do - if not item.fullName then - p.error("Failed to understand NuGet API response (package '%s' version '%s' packageEntry has no fullName)", id, version) - end + packageAPIInfo.packageEntries = {} - table.insert(packageAPIInfo.packageEntries, path.translate(item.fullName)) + for _, item in ipairs(response.packageEntries) do + if not item.fullName then + p.error("Failed to understand NuGet API response (package '%s' version '%s' packageEntry has no fullName)", id, version) end - if #packageAPIInfo.packageEntries == 0 then - p.error("NuGet package '%s' file listing is empty", id) - end + table.insert(packageAPIInfo.packageEntries, path.translate(item.fullName)) + end - if response.frameworkAssemblyGroup then - p.warn("NuGet package '%s' may depend on .NET Framework assemblies - package dependencies are currently unimplemented", id) - end + if #packageAPIInfo.packageEntries == 0 then + p.error("NuGet package '%s' file listing is empty", id) + end + + if response.frameworkAssemblyGroup then + p.warn("NuGet package '%s' may depend on .NET Framework assemblies - package dependencies are currently unimplemented", id) end if response.dependencyGroups then diff --git a/modules/vstudio/vs2010_vcxproj.lua b/modules/vstudio/vs2010_vcxproj.lua index 8c56d5713f..4bdfecb605 100644 --- a/modules/vstudio/vs2010_vcxproj.lua +++ b/modules/vstudio/vs2010_vcxproj.lua @@ -2148,16 +2148,28 @@ end end - local function nuGetTargetsFile(prj, package) + local function nuGetTargetsFile(prj, package, extension) local packageAPIInfo = vstudio.nuget2010.packageAPIInfo(prj, package) - return p.vstudio.path(prj, p.filename(prj.workspace, string.format("packages\\%s.%s\\build\\native\\%s.targets", vstudio.nuget2010.packageId(package), packageAPIInfo.verbatimVersion or packageAPIInfo.version, vstudio.nuget2010.packageId(package)))) + if not packageAPIInfo.packageEntries then + return nil + end + for _, entry in ipairs(packageAPIInfo.packageEntries) do + if path.getextension(entry) == extension then + local packageRootPath = p.filename(prj.workspace, string.format("packages\\%s.%s\\", vstudio.nuget2010.packageId(package), packageAPIInfo.verbatimVersion or packageAPIInfo.version)) + return p.vstudio.path(prj, path.join(packageRootPath, entry)) + end + end + + return nil end function m.importNuGetTargets(prj) if not vstudio.nuget2010.supportsPackageReferences(prj) then for i = 1, #prj.nuget do - local targetsFile = nuGetTargetsFile(prj, prj.nuget[i]) - p.x('', targetsFile, targetsFile) + local targetsFile = nuGetTargetsFile(prj, prj.nuget[i], ".targets") + if targetsFile then + p.x('', targetsFile, targetsFile) + end end end end @@ -2178,8 +2190,14 @@ p.pop('') for i = 1, #prj.nuget do - local targetsFile = nuGetTargetsFile(prj, prj.nuget[i]) - p.x('', targetsFile, targetsFile) + local propsFile = nuGetTargetsFile(prj, prj.nuget[i], ".props") + if propsFile then + p.x('', propsFile, propsFile) + end + local targetsFile = nuGetTargetsFile(prj, prj.nuget[i], ".targets") + if targetsFile then + p.x('', targetsFile, targetsFile) + end end p.pop('') end @@ -2201,6 +2219,7 @@ return { m.importGroupSettings, m.importRuleSettings, + m.importNuGetProps, m.importBuildCustomizationsProps } end @@ -2230,6 +2249,17 @@ end end + function m.importNuGetProps(prj) + if not vstudio.nuget2010.supportsPackageReferences(prj) then + for i = 1, #prj.nuget do + local propsFile = nuGetTargetsFile(prj, prj.nuget[i], ".props") + if propsFile then + p.x('', propsFile, propsFile) + end + end + end + end + function m.importBuildCustomizationsProps(prj) for i, build in ipairs(prj.buildcustomizations) do