This repository was archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task377921:Support DotnetPlatform nuget packages in Nue (#18)
* Task377921:Support DotnetPlatform nuget packages in Nue * Updated: To set Feed field for packageInfo. * Updated * Rename parameter name * Updated: Modify to regular expression to match * Updated * Fix Bug: if the TFM is netcoreapp3.0 or net5.0, this should cover everything like: netstandard2.0, netstandard1.0 * Updated
- Loading branch information
Showing
8 changed files
with
336 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,83 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{C8046141-6E78-44B8-BAD8-D83A19E8E77B}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Nue.StandardResolver</RootNamespace> | ||
<AssemblyName>Nue.StandardResolver</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.Build" /> | ||
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.ComponentModel.Composition" /> | ||
<Reference Include="System.Console, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.IdentityModel" /> | ||
<Reference Include="System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" /> | ||
<Reference Include="System.Net.Http.WebRequest" /> | ||
<Reference Include="System.Security" /> | ||
<Reference Include="System.ServiceModel" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Resolver.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Nue.Core\Nue.Core.csproj"> | ||
<Project>{6d7568ae-c944-4c70-8da6-54f983689972}</Project> | ||
<Name>Nue.Core</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<Content Include="custom.nuget.config"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<None Include="packages.config"> | ||
<SubType>Designer</SubType> | ||
</None> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{C8046141-6E78-44B8-BAD8-D83A19E8E77B}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Nue.StandardResolver</RootNamespace> | ||
<AssemblyName>Nue.StandardResolver</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.Build" /> | ||
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.ComponentModel.Composition" /> | ||
<Reference Include="System.Console, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.IdentityModel" /> | ||
<Reference Include="System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" /> | ||
<Reference Include="System.IO.Compression.FileSystem" /> | ||
<Reference Include="System.IO.Compression.ZipFile, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll</HintPath> | ||
<Private>True</Private> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Net.Http.WebRequest" /> | ||
<Reference Include="System.Security" /> | ||
<Reference Include="System.ServiceModel" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="PackageDownloder.cs" /> | ||
<Compile Include="Resolver.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Nue.Core\Nue.Core.csproj"> | ||
<Project>{6d7568ae-c944-4c70-8da6-54f983689972}</Project> | ||
<Name>Nue.Core</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<Content Include="custom.nuget.config"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<None Include="packages.config"> | ||
<SubType>Designer</SubType> | ||
</None> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using System; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Net; | ||
|
||
namespace Nue.StandardResolver | ||
{ | ||
public class PackageDownloder | ||
{ | ||
private string rootUrl = "http://nuget.org/api/v2/package/"; | ||
private string outPutPath; | ||
private string fileName; | ||
private string packageId; | ||
private string version; | ||
private bool overwrite; | ||
public string Url | ||
{ | ||
get | ||
{ | ||
var url = CombineUriToString(rootUrl, packageId); | ||
if (!string.IsNullOrEmpty(version)) | ||
{ | ||
url = $"{url}/{version}"; | ||
} | ||
|
||
return url; | ||
} | ||
} | ||
|
||
public PackageDownloder(string outPutPath, string packageId, string version, bool overwrite = false) | ||
{ | ||
this.outPutPath = outPutPath; | ||
this.packageId = packageId; | ||
this.overwrite = overwrite; | ||
this.version = version; | ||
} | ||
|
||
public void DownloadPackage() | ||
{ | ||
if (string.IsNullOrEmpty(outPutPath)) | ||
{ | ||
Console.WriteLine($"[error] outPutPath cannot be empty"); return; | ||
} | ||
|
||
if (string.IsNullOrEmpty(packageId)) | ||
{ | ||
Console.WriteLine($"[error] packageId cannot be empty"); return; | ||
} | ||
|
||
if (!Directory.Exists(outPutPath)) | ||
{ | ||
Directory.CreateDirectory(outPutPath); | ||
} | ||
|
||
var request = WebRequest.Create(Url) as HttpWebRequest; | ||
var response = request.GetResponse() as HttpWebResponse; | ||
fileName = response.Headers["Content-Disposition"]; | ||
if (string.IsNullOrEmpty(fileName)) | ||
{ | ||
fileName = response.ResponseUri.Segments[response.ResponseUri.Segments.Length - 1]; | ||
} | ||
else | ||
{ | ||
fileName = fileName.Remove(0, fileName.IndexOf("filename=") + 9); | ||
} | ||
|
||
using (var responseStream = response.GetResponseStream()) | ||
{ | ||
long totalLength = response.ContentLength; | ||
using (var stream = new FileStream(Path.Combine(outPutPath, fileName), overwrite ? FileMode.Create : FileMode.CreateNew)) | ||
{ | ||
byte[] bArr = new byte[1024]; | ||
int size; | ||
while ((size = responseStream.Read(bArr, 0, bArr.Length)) > 0) | ||
{ | ||
stream.Write(bArr, 0, size); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void Unzip() | ||
{ | ||
ModifyFileNameExtension(); | ||
var sourceFileName = Path.Combine(outPutPath, fileName); | ||
var zipPath = Path.Combine(outPutPath, $"{Path.GetFileNameWithoutExtension(sourceFileName)}"); | ||
if (!Directory.Exists(zipPath)) | ||
{ | ||
Directory.CreateDirectory(zipPath); | ||
} | ||
|
||
ZipFile.ExtractToDirectory(fileName, zipPath); | ||
} | ||
|
||
private void ModifyFileNameExtension() | ||
{ | ||
var sourceFileName = Path.Combine(outPutPath, fileName); | ||
var destFileName = Path.Combine(outPutPath, $"{Path.GetFileNameWithoutExtension(sourceFileName)}.zip"); | ||
File.Move(sourceFileName, destFileName); | ||
fileName = destFileName; | ||
} | ||
|
||
private string CombineUriToString(string baseUri, string relativeOrAbsoluteUri) | ||
{ | ||
return new Uri(new Uri(baseUri), relativeOrAbsoluteUri).ToString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.