Merge pull request #734 from aleksijuvani/nuget-fixes

NuGet fixes
This commit is contained in:
Tom van Dijck 2017-04-24 13:43:41 -07:00 committed by GitHub
commit 473b2f1e36
14 changed files with 644 additions and 145 deletions

View File

@ -790,6 +790,13 @@
tokens = true,
}
api.register {
name = "nugetsource",
scope = "project",
kind = "string",
tokens = true,
}
api.register {
name = "objdir",
scope = "config",
@ -1488,6 +1495,7 @@
exceptionhandling "Default"
rtti "Default"
symbols "Default"
nugetsource "https://api.nuget.org/v3/index.json"
-- Setting a default language makes some validation easier later

View File

@ -12,23 +12,6 @@
local config = p.config
--
-- All valid .NET Framework versions, from oldest to newest.
--
vstudio.frameworkVersions =
{
"1.0",
"1.1",
"2.0",
"3.0",
"3.5",
"4.0",
"4.5",
"4.6",
}
--
-- Mapping tables from Premake systems and architectures to Visual Studio
-- identifiers. Broken out as tables so new values can be pushed in by

View File

@ -21,20 +21,6 @@
p.escaper(vs2005.esc)
premake.generate(wks, ".sln", vstudio.sln2005.generate)
if _ACTION >= "vs2010" then
-- Skip generation of empty NuGet packages.config files
if p.workspace.hasProject(wks, function(prj) return #prj.nuget > 0 end) then
premake.generate(
{
location = path.join(wks.location, "packages.config"),
workspace = wks
},
nil,
vstudio.nuget2010.generatePackagesConfig
)
end
end
end

View File

@ -368,33 +368,95 @@
function cs2005.nuGetReferences(prj)
if _ACTION >= "vs2010" then
for i = 1, #prj.nuget do
local package = prj.nuget[i]
_x(2, '<Reference Include="%s">', vstudio.nuget2010.packageId(package))
for _, package in ipairs(prj.nuget) do
local id = vstudio.nuget2010.packageId(package)
local packageAPIInfo = vstudio.nuget2010.packageAPIInfo(prj, package)
-- We need to write HintPaths for all supported framework
-- versions. The last HintPath will override any previous
-- HintPaths (if the condition is met that is).
local cfg = p.project.getfirstconfig(prj)
local action = premake.action.current()
local targetFramework = cfg.dotnetframework or action.vstudio.targetFramework
for _, frameworkVersion in ipairs(cs2005.identifyFrameworkVersions(prj)) do
local assembly = vstudio.path(
prj,
p.filename(
prj.solution,
string.format(
"packages\\%s\\lib\\%s\\%s.dll",
vstudio.nuget2010.packageName(package),
cs2005.formatNuGetFrameworkVersion(frameworkVersion),
vstudio.nuget2010.packageId(package)
)
)
)
-- This is a bit janky. To compare versions, we extract all
-- numbers from the given string and right-pad the result with
-- zeros. Then we can just do a lexicographical compare on the
-- resulting strings.
--
-- This is so that we can compare version strings such as
-- "4.6" and "net451" with each other.
_x(3, '<HintPath Condition="Exists(\'%s\')">%s</HintPath>', assembly, assembly)
local function makeVersionComparable(a)
local numbers = ""
for number in a:gmatch("%d") do
numbers = numbers .. number
end
return string.format("%-10d", numbers):gsub(" ", "0")
end
_p(3, '<Private>True</Private>')
_p(2, '</Reference>')
local targetVersion = makeVersionComparable(targetFramework)
-- Figure out what folder contains the files for the nearest
-- supported .NET Framework version.
local files = {}
local bestVersion, bestFolder
for _, file in ipairs(packageAPIInfo.packageEntries) do
-- If this exporter ever supports frameworks such as
-- "netstandard1.3", "sl4", "sl5", "uap10", "wp8" or
-- "wp71", this code will need changing to match the right
-- folders.
local folder = file:match("^lib\\net(%d+)\\")
if folder and path.hasextension(file, ".dll") then
files[folder] = files[folder] or {}
table.insert(files[folder], file)
local version = makeVersionComparable(file:match("lib\\net(%d+)\\"))
if version <= targetVersion and (not bestVersion or version > bestVersion) then
bestVersion = version
bestFolder = folder
end
end
end
if not bestVersion then
p.error("NuGet package '%s' is not compatible with project '%s' .NET Framework version '%s'", id, prj.name, targetFramework)
end
-- Now, add references for all DLLs in that folder.
for _, file in ipairs(files[bestFolder]) do
-- There's some stuff missing from this include that we
-- can't get from the API and would need to download and
-- extract the package to figure out. It looks like we can
-- just omit it though.
--
-- So, for example, instead of:
--
-- <Reference Include="nunit.framework, Version=3.6.1.0,
-- <Culture=neutral, PublicKeyToken=2638cd05610744eb,
-- <processorArchitecture=MSIL">
--
-- We're just outputting:
--
-- <Reference Include="nunit.framework">
_x(2, '<Reference Include="%s">', path.getbasename(file))
_x(3, '<HintPath>%s</HintPath>', vstudio.path(prj, p.filename(prj.solution, string.format("packages\\%s.%s\\%s", id, packageAPIInfo.verbatimVersion or packageAPIInfo.version, file))))
if config.isCopyLocal(prj, package, true) then
_p(3, '<Private>True</Private>')
else
_p(3, '<Private>False</Private>')
end
_p(2, '</Reference>')
end
end
end
end
@ -485,32 +547,6 @@
end
--
-- Build and return a list of all .NET Framework versions up to and including
-- the project's framework version.
--
function cs2005.identifyFrameworkVersions(prj)
local frameworks = {}
local cfg = p.project.getfirstconfig(prj)
local action = premake.action.current()
local targetFramework = cfg.dotnetframework or action.vstudio.targetFramework
for _, frameworkVersion in ipairs(vstudio.frameworkVersions) do
if frameworkVersion == targetFramework then
break
end
table.insert(frameworks, frameworkVersion)
end
table.insert(frameworks, targetFramework)
return frameworks
end
--
-- When given a .NET Framework version, returns it formatted for NuGet.
--

View File

@ -72,6 +72,18 @@
premake.generate(prj, ".vcxproj.filters", vstudio.vc2010.generateFilters)
end
end
-- Skip generation of empty packages.config files
local packages = p.capture(function() vstudio.nuget2010.generatePackagesConfig(prj) end)
if #packages > 0 then
p.generate(prj, "packages.config", function() p.outln(packages) end)
end
-- Skip generation of empty NuGet.Config files
local config = p.capture(function() vstudio.nuget2010.generateNuGetConfig(prj) end)
if #config > 0 then
p.generate(prj, "NuGet.Config", function() p.outln(config) end)
end
end

View File

@ -11,16 +11,14 @@
local nuget2010 = p.vstudio.nuget2010
local cs2005 = p.vstudio.cs2005
local packageAPIInfos = {}
local packageSourceInfos = {}
--
-- These functions take the package string as an argument and give you
-- information about it.
--
function nuget2010.packageName(package)
return package:gsub(":", ".")
end
function nuget2010.packageId(package)
return package:sub(0, package:find(":") - 1)
end
@ -29,21 +27,7 @@
return package:sub(package:find(":") + 1, -1)
end
local function packageProject(wks, package)
for prj in p.workspace.eachproject(wks) do
for i = 1, #prj.nuget do
local projectPackage = prj.nuget[i]
if projectPackage == package then
return prj
end
end
end
end
function nuget2010.packageFramework(wks, package)
local prj = packageProject(wks, package)
function nuget2010.packageFramework(prj)
if p.project.isdotnet(prj) then
local cfg = p.project.getfirstconfig(prj)
local action = premake.action.current()
@ -54,33 +38,244 @@
end
end
function nuget2010.packageAPIInfo(prj, package)
local id = nuget2010.packageId(package)
local version = nuget2010.packageVersion(package)
if not packageSourceInfos[prj.nugetsource] then
local packageSourceInfo = {}
printf("Examining NuGet package source '%s'...", prj.nugetsource)
io.flush()
local response, err, code = http.get(prj.nugetsource)
if err ~= "OK" then
p.error("NuGet API error (%d)\n%s", code, err)
end
response, err = json.decode(response)
if not response then
p.error("Failed to decode NuGet API response (%s)", err)
end
if not response.resources then
p.error("Failed to understand NuGet API response (no resources in response)", id)
end
local packageDisplayMetadataUriTemplate, catalog
for _, resource in ipairs(response.resources) do
if not resource["@id"] then
p.error("Failed to understand NuGet API response (no resource['@id'])")
end
if not resource["@type"] then
p.error("Failed to understand NuGet API response (no resource['@type'])")
end
if resource["@type"]:find("PackageDisplayMetadataUriTemplate") == 1 then
packageDisplayMetadataUriTemplate = resource
end
if resource["@type"]:find("Catalog") == 1 then
catalog = resource
end
end
if not packageDisplayMetadataUriTemplate then
p.error("Failed to understand NuGet API response (no PackageDisplayMetadataUriTemplate resource)")
end
if not catalog then
if prj.nugetsource == "https://api.nuget.org/v3/index.json" then
p.error("Failed to understand NuGet API response (no Catalog resource)")
else
p.error("Package source is not a NuGet gallery - non-gallery sources are currently unsupported", prj.nugetsource, prj.name)
end
end
packageSourceInfo.packageDisplayMetadataUriTemplate = packageDisplayMetadataUriTemplate
packageSourceInfo.catalog = catalog
packageSourceInfos[prj.nugetsource] = packageSourceInfo
end
if not packageAPIInfos[package] then
local packageAPIInfo = {}
printf("Examining NuGet package '%s'...", id)
io.flush()
local response, err, code = http.get(packageSourceInfos[prj.nugetsource].packageDisplayMetadataUriTemplate["@id"]:gsub("{id%-lower}", id:lower()))
if err ~= "OK" then
if code == 404 then
p.error("NuGet package '%s' for project '%s' couldn't be found in the repository", id, prj.name)
else
p.error("NuGet API error (%d)\n%s", code, err)
end
end
response, err = json.decode(response)
if not response then
p.error("Failed to decode NuGet API response (%s)", err)
end
if not response.items or #response.items == 0 then
p.error("Failed to understand NuGet API response (no pages for package '%s')", id)
end
local items = {}
for _, page in ipairs(response.items) do
if not page.items or #page.items == 0 then
p.error("Failed to understand NuGet API response (got a page with no items for package '%s')", id)
end
for _, item in ipairs(page.items) do
table.insert(items, item)
end
end
local versions = {}
for _, item in ipairs(items) do
if not item.catalogEntry then
p.error("Failed to understand NuGet API response (subitem of package '%s' has no catalogEntry)", id)
end
if not item.catalogEntry.version then
p.error("Failed to understand NuGet API response (subitem of package '%s' has no catalogEntry.version)", id)
end
if not item.catalogEntry["@id"] then
p.error("Failed to understand NuGet API response (subitem of package '%s' has no catalogEntry['@id'])", id)
end
table.insert(versions, item.catalogEntry.version)
end
if not table.contains(versions, version) then
local options = table.translate(versions, function(value) return "'" .. value .. "'" end)
options = table.concat(options, ", ")
p.error("'%s' is not a valid version for NuGet package '%s' (options are: %s)", version, id, options)
end
for _, item in ipairs(items) do
if item.catalogEntry.version == version then
local response, err, code = http.get(item.catalogEntry["@id"])
if err ~= "OK" then
if code == 404 then
p.error("NuGet package '%s' version '%s' couldn't be found in the repository even though the API reported that it exists", id, version)
else
p.error("NuGet API error (%d)\n%s", code, err)
end
end
response, err = json.decode(response)
if not response then
p.error("Failed to decode NuGet API response (%s)", err)
end
if not response.verbatimVersion and not response.version then
p.error("Failed to understand NuGet API response (package '%s' version '%s' has no verbatimVersion or version)", id, version)
end
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
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
table.insert(packageAPIInfo.packageEntries, path.translate(item.fullName))
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
end
if response.dependencyGroups then
p.warn("NuGet package '%s' may depend on other packages - package dependencies are currently unimplemented", id)
end
break
end
end
packageAPIInfos[package] = packageAPIInfo
end
return packageAPIInfos[package]
end
--
-- Generates the packages.config file.
--
function nuget2010.generatePackagesConfig(obj)
local wks = obj.workspace
local done = {}
local packages = {}
for prj in p.workspace.eachproject(wks) do
for i = 1, #prj.nuget do
local package = prj.nuget[i]
if not done[package] then
done[package] = true
table.insert(packages, package)
end
end
end
function nuget2010.generatePackagesConfig(prj)
if #prj.nuget > 0 then
p.w('<?xml version="1.0" encoding="utf-8"?>')
p.push('<packages>')
for _, package in ipairs(packages) do
p.x('<package id="%s" version="%s" targetFramework="%s" />', nuget2010.packageId(package), nuget2010.packageVersion(package), nuget2010.packageFramework(wks, package))
for _, package in ipairs(prj.nuget) do
p.x('<package id="%s" version="%s" targetFramework="%s" />', nuget2010.packageId(package), nuget2010.packageVersion(package), nuget2010.packageFramework(prj))
end
p.pop('</packages>')
end
end
--
-- Generates the NuGet.Config file.
--
function nuget2010.generateNuGetConfig(prj)
if #prj.nuget == 0 then
return
end
if prj.nugetsource == "https://api.nuget.org/v3/index.json" then
return
end
p.w('<?xml version="1.0" encoding="utf-8"?>')
p.push('<configuration>')
p.push('<packageSources>')
-- By specifying "<clear />", we ensure that only the source that we
-- define below is used. Otherwise it would just get added to the list
-- of package sources.
p.x('<clear />')
p.x('<add key="%s" value="%s" />', prj.nugetsource, prj.nugetsource)
p.pop('</packageSources>')
p.pop('</configuration>')
end

View File

@ -1546,7 +1546,8 @@
end
local function nuGetTargetsFile(prj, package)
return p.vstudio.path(prj, p.filename(prj.solution, string.format("packages\\%s\\build\\native\\%s.targets", vstudio.nuget2010.packageName(package), vstudio.nuget2010.packageId(package))))
local packageAPIInfo = vstudio.nuget2010.packageAPIInfo(prj, package)
return p.vstudio.path(prj, p.filename(prj.solution, string.format("packages\\%s.%s\\build\\native\\%s.targets", vstudio.nuget2010.packageId(package), packageAPIInfo.verbatimVersion or packageAPIInfo.version, vstudio.nuget2010.packageId(package))))
end
function m.importNuGetTargets(prj)

View File

@ -634,7 +634,7 @@
-- I need to look at them all.
for cfg in p.project.eachconfig(prj) do
table.foreachi(cfg.files, function(fname)
local function addFile(fname)
-- If this is the first time I've seen this file, start a new
-- file configuration for it. Track both by key for quick lookups
@ -648,7 +648,17 @@
p.fileconfig.addconfig(files[fname], cfg)
end)
end
table.foreachi(cfg.files, addFile)
-- If this project uses NuGet, we need to add the generated
-- packages.config file to the project. Is there a better place to
-- do this?
if #prj.nuget > 0 then
addFile("packages.config")
end
end
-- Alpha sort the indices, so I will get consistent results in

View File

@ -39,6 +39,7 @@
return {
m.workspaceHasConfigs,
m.uniqueProjectIds,
m.uniqueProjectLocationsWithNuGet,
}
end
@ -60,6 +61,8 @@
m.actionSupportsKind,
m.projectRulesExist,
m.projectValuesInScope,
m.NuGetHasHTTP,
m.NuGetPackageStrings,
}
end
@ -222,6 +225,24 @@
end
function m.NuGetHasHTTP(prj)
if not http and #prj.nuget > 0 then
p.error("Premake was compiled with --no-curl, but Curl is required for NuGet support (project '%s' is referencing NuGet packages)", prj.name)
end
end
function m.NuGetPackageStrings(prj)
for _, package in ipairs(prj.nuget) do
local components = package:explode(":")
if #components ~= 2 or #components[1] == 0 or #components[2] == 0 then
p.error("NuGet package '%s' in project '%s' is invalid - please give packages in the format 'id:version', e.g. 'NUnit:3.6.1'", package, prj.name)
end
end
end
function m.uniqueProjectIds(wks)
local uuids = {}
for prj in p.workspace.eachproject(wks) do
@ -233,6 +254,29 @@
end
function m.uniqueProjectLocationsWithNuGet(wks)
local locations = {}
for prj in p.workspace.eachproject(wks) do
local function fail()
p.error("projects '%s' and '%s' cannot have the same location when using NuGet with different packages (packages.config conflict)", locations[prj.location].name, prj.name)
end
if locations[prj.location] and #locations[prj.location].nuget > 0 and #prj.nuget > 0 then
if #locations[prj.location].nuget ~= #prj.nuget then
fail()
end
for i, package in ipairs(locations[prj.location].nuget) do
if prj.nuget[i] ~= package then
fail()
end
end
end
locations[prj.location] = prj
end
end
function m.workspaceHasConfigs(wks)
if not wks.configurations or #wks.configurations == 0 then
p.error("workspace '%s' does not contain any configurations", wks.name)

View File

@ -70,6 +70,8 @@ return {
"actions/vstudio/cs2005/test_debug_props.lua",
"actions/vstudio/cs2005/test_files.lua",
"actions/vstudio/cs2005/test_icon.lua",
"actions/vstudio/cs2005/test_nuget_config.lua",
"actions/vstudio/cs2005/test_nuget_packages_config.lua",
"actions/vstudio/cs2005/test_output_props.lua",
"actions/vstudio/cs2005/projectelement.lua",
"actions/vstudio/cs2005/test_platform_groups.lua",
@ -85,7 +87,6 @@ return {
"actions/vstudio/sln2005/test_projects.lua",
"actions/vstudio/sln2005/test_platforms.lua",
"actions/vstudio/sln2005/test_sections.lua",
"actions/vstudio/sln2005/test_nuget_packages_config.lua",
-- Visual Studio 2002-2008 C/C++ projects
"actions/vstudio/vc200x/test_assembly_refs.lua",
@ -128,6 +129,7 @@ return {
"actions/vstudio/vc2010/test_link.lua",
"actions/vstudio/vc2010/test_manifest.lua",
"actions/vstudio/vc2010/test_nmake_props.lua",
"actions/vstudio/vc2010/test_nuget_packages_config.lua",
"actions/vstudio/vc2010/test_output_props.lua",
"actions/vstudio/vc2010/test_platform_toolset.lua",
"actions/vstudio/vc2010/test_project_configs.lua",

View File

@ -147,43 +147,113 @@
-- NuGet packages should get references.
--
function suite.nuGetPackages()
function suite.nuGetPackages_net45()
dotnetframework "4.5"
nuget { "Newtonsoft.Json:7.0.1" }
nuget { "Newtonsoft.Json:10.0.2" }
prepare()
test.capture [[
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath Condition="Exists('packages\Newtonsoft.Json.7.0.1\lib\net10\Newtonsoft.Json.dll')">packages\Newtonsoft.Json.7.0.1\lib\net10\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('packages\Newtonsoft.Json.7.0.1\lib\net11\Newtonsoft.Json.dll')">packages\Newtonsoft.Json.7.0.1\lib\net11\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('packages\Newtonsoft.Json.7.0.1\lib\net20\Newtonsoft.Json.dll')">packages\Newtonsoft.Json.7.0.1\lib\net20\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('packages\Newtonsoft.Json.7.0.1\lib\net30\Newtonsoft.Json.dll')">packages\Newtonsoft.Json.7.0.1\lib\net30\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('packages\Newtonsoft.Json.7.0.1\lib\net35\Newtonsoft.Json.dll')">packages\Newtonsoft.Json.7.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll')">packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll')">packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
]]
end
--
-- NuGet packages shouldn't get HintPaths for .NET Framework
-- versions that the project doesn't support.
--
function suite.nuGetPackages_olderNET()
function suite.nuGetPackages_net30()
dotnetframework "3.0"
nuget { "Newtonsoft.Json:7.0.1" }
nuget { "Newtonsoft.Json:10.0.2" }
prepare()
test.capture [[
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath Condition="Exists('packages\Newtonsoft.Json.7.0.1\lib\net10\Newtonsoft.Json.dll')">packages\Newtonsoft.Json.7.0.1\lib\net10\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('packages\Newtonsoft.Json.7.0.1\lib\net11\Newtonsoft.Json.dll')">packages\Newtonsoft.Json.7.0.1\lib\net11\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('packages\Newtonsoft.Json.7.0.1\lib\net20\Newtonsoft.Json.dll')">packages\Newtonsoft.Json.7.0.1\lib\net20\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('packages\Newtonsoft.Json.7.0.1\lib\net30\Newtonsoft.Json.dll')">packages\Newtonsoft.Json.7.0.1\lib\net30\Newtonsoft.Json.dll</HintPath>
<HintPath>packages\Newtonsoft.Json.10.0.2\lib\net20\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
]]
end
--
-- If there are multiple assemblies in the NuGet package, they all should be
-- referenced.
--
function suite.nuGetPackages_multipleAssemblies()
dotnetframework "2.0"
nuget { "NUnit:3.6.1" }
prepare()
test.capture [[
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>packages\NUnit.3.6.1\lib\net20\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NUnit.System.Linq">
<HintPath>packages\NUnit.3.6.1\lib\net20\NUnit.System.Linq.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
]]
end
--
-- NuGet packages should respect copylocal() and the NoCopyLocal flag.
--
function suite.nugetPackages_onNoCopyLocal()
dotnetframework "2.0"
nuget { "NUnit:3.6.1" }
flags { "NoCopyLocal" }
prepare()
test.capture [[
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>packages\NUnit.3.6.1\lib\net20\nunit.framework.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NUnit.System.Linq">
<HintPath>packages\NUnit.3.6.1\lib\net20\NUnit.System.Linq.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
]]
end
function suite.nugetPackages_onCopyLocalListExclusion()
dotnetframework "2.0"
nuget { "NUnit:3.6.1" }
copylocal { "SomeOtherProject" }
prepare()
test.capture [[
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>packages\NUnit.3.6.1\lib\net20\nunit.framework.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NUnit.System.Linq">
<HintPath>packages\NUnit.3.6.1\lib\net20\NUnit.System.Linq.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
]]
end
function suite.nugetPackages_onCopyLocalListInclusion()
dotnetframework "2.0"
nuget { "NUnit:3.6.1" }
copylocal { "NUnit:3.6.1" }
prepare()
test.capture [[
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>packages\NUnit.3.6.1\lib\net20\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NUnit.System.Linq">
<HintPath>packages\NUnit.3.6.1\lib\net20\NUnit.System.Linq.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>

View File

@ -0,0 +1,82 @@
--
-- tests/actions/vstudio/cs2005/test_nuget_config.lua
-- Validate generation of NuGet.Config files for Visual Studio 2010 and newer
-- Copyright (c) 2017 Jason Perkins and the Premake project
--
local suite = test.declare("vstudio_cs2005_nuget_config")
local cs2005 = premake.vstudio.cs2005
local nuget2010 = premake.vstudio.nuget2010
--
-- Setup and teardown
--
local wks, prj
function suite.setup()
premake.action.set("vs2010")
wks = test.createWorkspace()
language "C#"
end
local function prepare(platform)
prj = test.getproject(wks, 1)
nuget2010.generateNuGetConfig(prj)
end
--
-- Shouldn't output a file if no packages or sources have been set.
--
function suite.noOutputIfNoPackages()
prepare()
test.isemptycapture()
end
--
-- Shouldn't output a file if no package sources have been set.
--
function suite.noOutputIfNoPackageSources()
dotnetframework "4.6"
nuget "NUnit:3.6.1"
prepare()
test.isemptycapture()
end
--
-- Shouldn't output a file if no packages have been set.
--
function suite.noOutputIfNoPackagesButSource()
dotnetframework "4.6"
nugetsource "https://www.myget.org/F/premake-nuget-test/api/v3/index.json"
prepare()
test.isemptycapture()
end
--
-- Writes the NuGet.Config file properly.
--
function suite.structureIsCorrect()
dotnetframework "4.6"
nuget "NUnit:3.6.1"
nugetsource "https://www.myget.org/F/premake-nuget-test/api/v3/index.json"
prepare()
test.capture [[
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="https://www.myget.org/F/premake-nuget-test/api/v3/index.json" value="https://www.myget.org/F/premake-nuget-test/api/v3/index.json" />
</packageSources>
</configuration>
]]
end

View File

@ -0,0 +1,57 @@
--
-- tests/actions/vstudio/cs2005/test_assembly_refs.lua
-- Validate generation of NuGet packages.config file for Visual Studio 2010 and newer.
-- Copyright (c) 2012-2015 Jason Perkins and the Premake project
--
local suite = test.declare("vstudio_cs2005_nuget_packages_config")
local cs2005 = premake.vstudio.cs2005
local nuget2010 = premake.vstudio.nuget2010
--
-- Setup and teardown
--
local wks, prj
function suite.setup()
premake.action.set("vs2010")
wks = test.createWorkspace()
language "C#"
end
local function prepare(platform)
prj = test.getproject(wks, 1)
nuget2010.generatePackagesConfig(prj)
end
--
-- Should not output anything if no packages have been set.
--
function suite.noOutputIfNoPackages()
prepare()
test.isemptycapture()
end
--
-- Writes the packages.config file properly.
--
function suite.structureIsCorrect()
dotnetframework "4.6"
nuget { "Newtonsoft.Json:10.0.2", "NUnit:3.6.1", "SSH.NET:2016.0.0" }
prepare()
test.capture [[
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net46" />
<package id="NUnit" version="3.6.1" targetFramework="net46" />
<package id="SSH.NET" version="2016.0.0" targetFramework="net46" />
</packages>
]]
end

View File

@ -1,11 +1,13 @@
--
-- tests/actions/vstudio/sln2005/test_nuget_packages_config.lua
-- tests/actions/vstudio/vc2010/test_nuget_packages_config.lua
-- Validate generation of NuGet packages.config file for Visual Studio 2010 and newer.
-- Copyright (c) 2016 Jason Perkins and the Premake project
-- Copyright (c) 2017 Jason Perkins and the Premake project
--
local suite = test.declare("vstudio_sln2005_nuget_packages_config")
local suite = test.declare("vs2010_nuget_packages_config")
local vc2010 = premake.vstudio.vc2010
local nuget2010 = premake.vstudio.nuget2010
local project = premake.project
--
@ -21,10 +23,21 @@
local function prepare()
local prj = premake.solution.getproject(wks, 1)
nuget2010.generatePackagesConfig({ workspace = wks })
nuget2010.generatePackagesConfig(prj)
end
--
-- Should not output anything if no packages have been set.
--
function suite.noOutputIfNoPackages()
prepare()
test.isemptycapture()
end
--
-- Writes the packages.config file properly.
--