cli to msbuild
This commit is contained in:
parent
c83ff84370
commit
90cfc29492
5 changed files with 26 additions and 18 deletions
5
.vscode/tasks.json
vendored
5
.vscode/tasks.json
vendored
|
|
@ -28,15 +28,14 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "buildcli",
|
"label": "buildcli",
|
||||||
"command": "dotnet",
|
"command": "msbuild",
|
||||||
"type": "process",
|
"type": "process",
|
||||||
"args": [
|
"args": [
|
||||||
"build",
|
|
||||||
"src/nuget-cli",
|
"src/nuget-cli",
|
||||||
"/p:Configuration=Debug",
|
"/p:Configuration=Debug",
|
||||||
"/property:GenerateFullPaths=true",
|
"/property:GenerateFullPaths=true",
|
||||||
"/consoleloggerparameters:NoSummary",
|
"/consoleloggerparameters:NoSummary",
|
||||||
"--ignore-failed-sources"
|
"/restore"
|
||||||
],
|
],
|
||||||
"problemMatcher": "$msCompile"
|
"problemMatcher": "$msCompile"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace nuget_cli
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates HTTP POST request & uploads database to server. Author : Farhan Ghumra
|
/// Creates HTTP POST request & uploads database to server. Author : Farhan Ghumra
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static internal async Task UploadFilesToServer(
|
static internal void UploadFilesToServer(
|
||||||
this PushReport report, Uri uri,
|
this PushReport report, Uri uri,
|
||||||
FileInfo fi, string apikey)
|
FileInfo fi, string apikey)
|
||||||
{
|
{
|
||||||
|
|
@ -30,10 +30,10 @@ namespace nuget_cli
|
||||||
{
|
{
|
||||||
using (HttpClient client = new HttpClient())
|
using (HttpClient client = new HttpClient())
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
// client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
|
||||||
client.DefaultRequestHeaders.Add("X-NuGet-Client-Version", clientVersion);
|
// client.DefaultRequestHeaders.Add("X-NuGet-Client-Version", clientVersion);
|
||||||
client.DefaultRequestHeaders.Add("X-NuGet-ApiKey", apikey);
|
// client.DefaultRequestHeaders.Add("X-NuGet-ApiKey", apikey);
|
||||||
var dispo = new ContentDispositionHeaderValue("file");
|
var dispo = new ContentDispositionHeaderValue("file");
|
||||||
dispo.FileName = fi.Name;
|
dispo.FileName = fi.Name;
|
||||||
dispo.CreationDate = fi.CreationTime;
|
dispo.CreationDate = fi.CreationTime;
|
||||||
|
|
@ -44,17 +44,26 @@ namespace nuget_cli
|
||||||
Stream fileStream = fi.OpenRead();
|
Stream fileStream = fi.OpenRead();
|
||||||
var streamcontent = new StreamContent(fileStream);
|
var streamcontent = new StreamContent(fileStream);
|
||||||
streamcontent.Headers.ContentDisposition = dispo;
|
streamcontent.Headers.ContentDisposition = dispo;
|
||||||
formdata.Add(streamcontent, "file", fi.Name);
|
formdata.Add(streamcontent, fi.Name, fi.Name);
|
||||||
|
|
||||||
// content.Add(formdata);
|
// content.Add(formdata);
|
||||||
|
client.BaseAddress = uri;
|
||||||
|
HttpRequestMessage put = new HttpRequestMessage(HttpMethod.Put, uri);
|
||||||
|
put.Content = formdata;
|
||||||
|
put.Headers.Add("X-NuGet-Client-Version", clientVersion);
|
||||||
|
put.Headers.Add("X-NuGet-ApiKey", apikey);
|
||||||
|
put.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
|
||||||
var response = await client.PutAsync(uri, formdata);
|
|
||||||
response.EnsureSuccessStatusCode();
|
Task<HttpResponseMessage> response = client.SendAsync(put);
|
||||||
report.StatusCode = response.StatusCode.ToString();
|
response.RunSynchronously();
|
||||||
var respstream = await response.Content.ReadAsStreamAsync();
|
|
||||||
|
response.Result.EnsureSuccessStatusCode();
|
||||||
|
report.StatusCode = response.Result.StatusCode.ToString();
|
||||||
|
var respstream = response.Result.Content.ReadAsStreamAsync().Result;
|
||||||
var sr = new StreamReader(respstream);
|
var sr = new StreamReader(respstream);
|
||||||
|
|
||||||
report.Message = await sr.ReadToEndAsync();
|
report.Message = sr.ReadToEndAsync().Result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace nuget_cli
|
namespace nuget_cli
|
||||||
{
|
{
|
||||||
[Display(Name="nuget_cli")]
|
|
||||||
partial class Program
|
partial class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace nuget_cli
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await report.UploadFilesToServer(new Uri(source), fi, apikey);
|
await Task.Run(() => report.UploadFilesToServer(new Uri(source), fi, apikey));
|
||||||
}
|
}
|
||||||
catch (WebException ex)
|
catch (WebException ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>net472</TargetFramework>
|
||||||
<RootNamespace>nuget_cli</RootNamespace>
|
<RootNamespace>nuget_cli</RootNamespace>
|
||||||
<UserSecretsId>45b74c62-05bc-4603-95b4-3e80ae2fdf50</UserSecretsId>
|
<UserSecretsId>45b74c62-05bc-4603-95b4-3e80ae2fdf50</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Mono.Options" Version="5.3.0" />
|
<PackageReference Include="Mono.Options" Version="5.3.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
|
<Reference Include="System.Net.Http" Version="4.0.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue