Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openxt
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
msc
openxt
Commits
55fb4225
There was an error fetching the commit references. Please try again later.
Commit
55fb4225
authored
4 years ago
by
Bensong Liu
Browse files
Options
Downloads
Patches
Plain Diff
write a new nuget download
parent
beedcbf7
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+0
-1
0 additions, 1 deletion
.gitignore
tools/build-and-pack.sh
+1
-1
1 addition, 1 deletion
tools/build-and-pack.sh
tools/csproj-to-5/main.go
+0
-0
0 additions, 0 deletions
tools/csproj-to-5/main.go
tools/nuget-download-package/main.go
+133
-0
133 additions, 0 deletions
tools/nuget-download-package/main.go
with
134 additions
and
2 deletions
.gitignore
+
0
−
1
View file @
55fb4225
...
...
@@ -2,5 +2,4 @@
.vscode
openxt
csproj-to-5
*.tar.gz
This diff is collapsed.
Click to expand it.
tools/build-and-pack.sh
+
1
−
1
View file @
55fb4225
...
...
@@ -15,7 +15,7 @@ function build () {
rm
-rf
bin/
GOOS
=
"
$os
"
GOARCH
=
"
$arch
"
go build
-o
"bin/openxt
$bin_tail
"
.
&&
GOOS
=
"
$os
"
GOARCH
=
"
$arch
"
go build
-o
"bin/csproj-to-5
$bin_tail
"
tools/csproj-to-5.go
&&
GOOS
=
"
$os
"
GOARCH
=
"
$arch
"
go build
-o
"bin/csproj-to-5
$bin_tail
"
tools/csproj-to-5
/main
.go
&&
tar
cvzf
"openxt-
$version
-
$os
-
$arch
.tar.gz"
bin
return
$?
...
...
This diff is collapsed.
Click to expand it.
tools/csproj-to-5.go
→
tools/csproj-to-5
/main
.go
+
0
−
0
View file @
55fb4225
File moved
This diff is collapsed.
Click to expand it.
tools/nuget-download-package/main.go
0 → 100644
+
133
−
0
View file @
55fb4225
package
main
import
(
"github.com/antchfx/xmlquery"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"sync"
)
/*
`dotnet add` has a bug:
If my csproj is using net462, and I run
dotnet add package Microsoft.Azure.Kusto.Cloud.Platform --package-directory ~/tmp/ttt --framework net462
It would say: Package Microsoft.Azure.Kusto.Cloud.Platform 9.1.0 is not compatible with net462
However, Microsoft.Azure.Kusto.Cloud.Platform 8.1.5 IS compatible with net462. It doesn't download at all!
dotnet add also requires a valid csproj. It's heavy, complex, and slow. It sucks.
Let's write a simple one!
*/
const
nugetConfigPath
=
"~/.nuget/NuGet/NuGet.Config"
func
panicErrorIfAny
(
err
error
,
title
string
)
{
if
err
!=
nil
{
panic
(
"[Error] on "
+
title
+
": "
+
err
.
Error
())
}
}
func
logErrorIfAny
(
err
error
,
title
string
)
{
if
err
!=
nil
{
log
.
Println
(
"[Error] on "
+
title
+
": "
+
err
.
Error
())
}
}
func
pkgVersionLeftIsGreater
(
left
,
right
string
)
bool
{
// return if left > right
return
true
}
var
nugetIndexJsonCache
[]
string
func
initNugetIndexJsonCache
(
pkgName
string
)
{
// download index.json from every source, and cache them in global variable.
nugetIndexJsonCache
=
[]
string
{}
f
,
err
:=
os
.
Open
(
nugetConfigPath
)
panicErrorIfAny
(
err
,
"Open "
+
nugetConfigPath
)
parsed
,
err
:=
xmlquery
.
Parse
(
f
)
panicErrorIfAny
(
err
,
"Parse XML "
+
nugetConfigPath
)
sources
:=
xmlquery
.
Find
(
parsed
,
"//configuration/packageSources/add"
)
var
wg
sync
.
WaitGroup
nugetIndexJsonCache_wlock
:=
sync
.
RWMutex
{}
for
_
,
source
:=
range
sources
{
// Parse xml
sname
,
surl
,
sauth_username
,
sauth_password
:=
""
,
""
,
""
,
""
for
_
,
attr
:=
range
source
.
Attr
{
if
attr
.
Name
.
Local
==
"key"
{
sname
=
attr
.
Value
}
else
if
attr
.
Name
.
Local
==
"value"
{
surl
=
attr
.
Value
}
}
auth_entries
:=
xmlquery
.
Find
(
parsed
,
"//configuration/packageSourceCredentials/"
+
sname
+
"/add"
)
for
_
,
auth_entry
:=
range
auth_entries
{
for
_
,
attr
:=
range
auth_entry
.
Attr
{
if
attr
.
Name
.
Local
==
"Username"
{
sauth_username
=
attr
.
Value
}
else
if
attr
.
Name
.
Local
==
"ClearTextPassword"
{
sauth_password
=
attr
.
Value
}
}
}
// Send the HTTP request and download index.json!
wg
.
Add
(
1
)
nugetIndexJsonCache
=
append
(
nugetIndexJsonCache
,
""
)
go
func
(
url
,
authu
,
authp
string
)
{
defer
wg
.
Done
()
req
,
err
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
panicErrorIfAny
(
err
,
"http.NewRequest"
)
if
authu
+
authp
!=
""
{
req
.
SetBasicAuth
(
authu
,
authp
)
}
resp
,
err
:=
http
.
DefaultClient
.
Do
(
req
)
logErrorIfAny
(
err
,
"download json"
)
defer
resp
.
Body
.
Close
()
resp_txt
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
logErrorIfAny
(
err
,
"download json"
)
if
len
(
resp_txt
)
>
0
{
nugetIndexJsonCache_wlock
.
Lock
()
nugetIndexJsonCache
=
append
(
nugetIndexJsonCache
,
string
(
resp_txt
))
nugetIndexJsonCache_wlock
.
Unlock
()
}
}(
surl
,
sauth_username
,
sauth_password
)
}
wg
.
Wait
()
}
// recursive. If package exists, it exit.
// One of [pkgVerBegin, pkgVerEnd] would be downloaded.
func
downloadPackageAndDeps
(
packageName
,
pkgVerBegin
,
pkgVerEnd
,
localRepoDir
string
)
{
}
// [pkgVerBegin, pkgVerEnd] is good for frameworkVersion.
func
decidePackageVersion
(
packageName
,
frameworkVersion
string
)
(
pkgVerBegin
,
pkgVerEnd
string
)
{
// Generated by curl-to-Go: https://mholt.github.io/curl-to-go
// curl -u bensl:xbwejuparq4ighqs4pjq6bqjqmxpzghhtqshql2uy3woi73ew6iq https://o365exchange.pkgs.visualstudio.com/959adb23-f323-4d52-8203-ff34e5cbeefa/_packaging/aacaa93f-61ac-420c-8b20-c17c5d2b52f1/nuget/v3/registrations2-semver2/microsoft.azure.kusto.cloud.platform/index.json
return
"1.1.1"
,
"8.8.8"
}
func
main
()
{
if
(
len
(
os
.
Args
)
<
4
)
{
log
.
Println
(
"Usage: nuget-download-package <packageName> <packageVersion/frameworkVersion> <localRepoDir>"
)
log
.
Println
(
"frameworkVersion maybe 'net472', 'netstandard2.0', 'netcoreapp3.1' ..."
)
os
.
Exit
(
1
)
}
pkgName
,
pkgVer
,
localRepoDir
:=
os
.
Args
[
1
],
os
.
Args
[
2
],
os
.
Args
[
3
]
if
strings
.
HasPrefix
(
pkgVer
,
"net"
)
{
_
,
pkgVer
=
decidePackageVersion
(
pkgName
,
pkgVer
)
}
downloadPackageAndDeps
(
pkgName
,
pkgVer
,
pkgVer
,
localRepoDir
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment