Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 44 additions & 19 deletions modules/vstudio/vs2010_nuget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,28 @@
--

function nuget2010.packageAPIInfo(prj, package)
if packageAPIInfos[package] then
return packageAPIInfos[package]
end

local id = nuget2010.packageId(package)
local version = nuget2010.packageVersion(package)

-- It's possible that NuGet already has this package in its cache. In
-- that case we can examine the nuspec file and the file listing
-- locally.

local function examinePackageFromCache()
-- It should be possible to implement this for platforms other than
-- Windows, but we'll need to figure out where the NuGet cache is on
-- these platforms (or if they even have one).

if not os.ishost("windows") then
return
end

local cachePath = path.translate(path.join(os.getenv("userprofile"), ".nuget/packages", id))

if os.isdir(cachePath) then
local function examinePackageFromDirectory(directory)
if os.isdir(directory) then
local packageAPIInfo = {}

printf("Examining cached NuGet package '%s'...", id)
printf("Examining NuGet package '%s' from '%s'...", id, path.translate(directory))
io.flush()

local versionPath = path.translate(path.join(cachePath, version))
local versionPath = path.translate(path.join(directory, version))

local nuspecPath = path.translate(path.join(versionPath, id .. ".nuspec"))
local nupkgPath = path.translate(path.join(versionPath, id .. "." .. version .. ".nupkg"))

if not os.isfile(nuspecPath) then
return
Expand All @@ -102,11 +97,21 @@

packageAPIInfo.packageEntries = {}

for _, file in ipairs(os.matchfiles(path.translate(path.join(versionPath, "**")))) do
local extension = path.getextension(file)
if zip then
local entries, err = zip.list(nupkgPath)

if extension ~= ".nupkg" and extension ~= ".sha512" then
table.insert(packageAPIInfo.packageEntries, path.translate(path.getrelative(versionPath, file)))
if err ~= nil then
p.warn("Cannot list entries of '" .. nupkgPath "'")
else
packageAPIInfo.packageEntries = entries
end
else
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
end
end

Expand All @@ -127,8 +132,28 @@
end
end

if os.isdir(prj.nugetsource) then
examinePackageFromDirectory(path.join(prj.nugetsource, id))

if packageAPIInfos[package] then
return packageAPIInfos[package]
else
p.error("Cannot find package '" .. package .. "' in local directory: " .. prj.nugetsource)
end
end

if not packageAPIInfos[package] then
examinePackageFromCache()
-- Examine package from cache directory

-- It should be possible to implement this for platforms other than
-- Windows, but we'll need to figure out where the NuGet cache is on
-- these platforms (or if they even have one).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write an issue to track that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, moved code BTW.
Not sure how Nuget is used outside MSVC.

Copy link
Member

@nickclark2016 nickclark2016 Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used with dotnet on MacOS, Linux, and Windows in addition to the native C++ packages on Windows. That said, Microsoft recommends vcpkg now for native projects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added #2630


if os.ishost("windows") then
local cachePath = path.join(os.getenv("userprofile"), ".nuget/packages", id)
examinePackageFromDirectory(cachePath)
end

end

-- If we didn't find the package from the cache, use the NuGet API
Expand Down
1 change: 1 addition & 0 deletions src/host/premake.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ static const luaL_Reg http_functions[] = {
#ifdef PREMAKE_COMPRESSION
static const luaL_Reg zip_functions[] = {
{ "extract", zip_extract },
{ "list", zip_list},
{ NULL, NULL }
};
#endif
Expand Down
1 change: 1 addition & 0 deletions src/host/premake.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ int http_download(lua_State* L);

#ifdef PREMAKE_COMPRESSION
int zip_extract(lua_State* L);
int zip_list(lua_State* L);
#endif

/* Engine interface */
Expand Down
33 changes: 33 additions & 0 deletions src/host/zip_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "premake.h"

#ifdef PREMAKE_COMPRESSION

#include "zip.h"

int zip_list(lua_State* L)
{
const char* src = luaL_checkstring(L, 1);

int err = 0;
struct zip* z_archive = zip_open(src, 0, &err);

if(!z_archive)
{
lua_newtable(L);
lua_pushstring(L, "Cannot open file");
return 2;
}
const zip_int64_t entries_count = zip_get_num_entries(z_archive, 0);
lua_createtable(L, entries_count, 0);
for(zip_int64_t i = 0; i != entries_count; ++i)
{
const char* full_name = zip_get_name(z_archive, i, 0);
lua_pushstring(L, full_name);
lua_rawseti(L, -2, i);
}
zip_close(z_archive);
lua_pushnil(L);
return 2;
}

#endif
12 changes: 10 additions & 2 deletions website/docs/nugetsource.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@ nugetsource ("url")

### Parameters ###

`url` is the NuGet v3 feed URL.
`url` is the NuGet v3 feed URL or local directory.

### Applies To ###

Project configurations.

### Availability ###

Premake 5.0.0-alpha12 or later.
Nuget "galleries" since Premake 5.0.0-alpha12 or later.
Local directory since Premake 5.0.0 or later.

### Examples ###

Set source to NuGet gallery.

```lua
nugetsource "https://api.nuget.org/v3/index.json"
```

Set source to local directory.

```lua
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment to both the original snippet and this snippet describing it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have been more specific. This is what I'm looking for: https://premake.github.io/docs/defines/ -- Not in the code block itself, but a snippet above describing what the example does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved.

nugetsource "c:/my_nuget_packages/"
```
### See Also ###

* [nuget](nuget.md)
17 changes: 17 additions & 0 deletions website/docs/zip/zip.list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Get list of file paths contained in an archive.

```lua
local entries, err = zip.list(sourceZip)
```

### Parameters ###
- `sourceZip` is the zip file which has to be extracted

### Return Value ###

A new table containing the path of files contained in the archive, following with error string.

### Availability ###

Premake 5.0.0 or later.

3 changes: 2 additions & 1 deletion website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ module.exports = {
type: 'category',
label: 'zip',
items: [
'zip/zip.extract'
'zip/zip.extract',
'zip/zip.list'
]
}
],
Expand Down
Loading