Skip to content

Commit 74be9a4

Browse files
Garvin CasimirGarvin Casimir
Garvin Casimir
authored and
Garvin Casimir
committed
Adding nuget package project
1 parent 569405e commit 74be9a4

12 files changed

+686
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{0451BAEF-DF2E-4B98-8644-94EE9415E389}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>DataTablesParser.NuGet</RootNamespace>
12+
<AssemblyName>DataTablesParser.NuGet</AssemblyName>
13+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14+
<TargetFrameworkProfile>
15+
</TargetFrameworkProfile>
16+
<FileAlignment>512</FileAlignment>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<PlatformTarget>AnyCPU</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<PlatformTarget>AnyCPU</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
38+
<PlatformTarget>AnyCPU</PlatformTarget>
39+
<OutputPath>bin\Debug\</OutputPath>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
42+
<PlatformTarget>AnyCPU</PlatformTarget>
43+
<OutputPath>bin\Release\</OutputPath>
44+
</PropertyGroup>
45+
<PropertyGroup>
46+
<StartupObject />
47+
</PropertyGroup>
48+
<ItemGroup>
49+
<Compile Include="Properties\AssemblyInfo.cs" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<None Include="NuGetPackage.ps1" />
53+
<None Include="NuGetSetup.ps1" />
54+
<None Include="NuGet.exe" />
55+
<None Include="NuGet.config" />
56+
<None Include="Package.nuspec">
57+
<SubType>Designer</SubType>
58+
</None>
59+
<None Include="tools\init.ps1" />
60+
<None Include="tools\install.ps1" />
61+
<None Include="tools\uninstall.ps1" />
62+
</ItemGroup>
63+
<ItemGroup>
64+
<Folder Include="content\" />
65+
</ItemGroup>
66+
<ItemGroup>
67+
<Content Include="lib\DataTablesParser.dll" />
68+
</ItemGroup>
69+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
70+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
71+
Other similar extension points exist, see Microsoft.Common.targets.
72+
<Target Name="BeforeBuild">
73+
</Target>-->
74+
<Target Name="AfterBuild">
75+
<Delete Files=".\NuGet.log" />
76+
<Exec WorkingDirectory="$(MSBuildProjectDirectory)" Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " ContinueOnError="True" Command="PowerShell.exe -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Unrestricted -Command &quot;&amp; {.\NuGetPackage.ps1} &quot;" IgnoreExitCode="true" />
77+
<Exec WorkingDirectory="$(MSBuildProjectDirectory)" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " ContinueOnError="True" Command="PowerShell.exe -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command &quot;&amp; {.\NuGetPackage.ps1 -Publish} &quot;" IgnoreExitCode="true" />
78+
<!-- Hack to get error code from powershell script and not powershell.exe -->
79+
<Exec Command="exit %errorlevel">
80+
<Output PropertyName="ExitCode" TaskParameter="ExitCode" />
81+
</Exec>
82+
<Message Text=" " Importance="High" />
83+
<Message Text="Exit Code: $(ExitCode)" />
84+
<Error Text="Encountered error(s) when creating package.%0aCheck the NuGet.log file for details." Condition=" '$(ExitCode)' == '1' " File="NuGet.log" />
85+
<Message Text="SUCCESS: Created package." Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' And '$(ExitCode)' == '0' " Importance="High" />
86+
<Message Text="SUCCESS: Published package." Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' And '$(ExitCode)' == '0' " Importance="High" />
87+
<Error Text="Created package but encountered error(s) when trying to publish it.%0aCheck the NuGet.log file for details." Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' And '$(ExitCode)' == '1' " File="NuGet.log" />
88+
</Target>
89+
</Project>

DataTablesParser.NuGet/NuGet.config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<apikeys>
4+
</apikeys>
5+
<packageSources>
6+
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
7+
</packageSources>
8+
</configuration>

DataTablesParser.NuGet/NuGet.exe

760 KB
Binary file not shown.
Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
Param (
2+
[switch]$Publish
3+
)
4+
5+
$ErrorActionPreference = "Stop"
6+
$ExitCode = 1
7+
8+
function Write-Log {
9+
10+
#region Parameters
11+
12+
[cmdletbinding()]
13+
Param(
14+
[Parameter(ValueFromPipeline=$true)]
15+
[array] $Messages,
16+
17+
[Parameter()] [ValidateSet("Error", "Warn", "Info")]
18+
[string] $Level = "Info",
19+
20+
[Parameter()]
21+
[Switch] $NoConsoleOut = $false,
22+
23+
[Parameter()]
24+
[String] $ForegroundColor = 'White',
25+
26+
[Parameter()] [ValidateRange(1,30)]
27+
[Int16] $Indent = 0,
28+
29+
[Parameter()]
30+
[IO.FileInfo] $Path = ".\NuGet.log",
31+
32+
[Parameter()]
33+
[Switch] $Clobber,
34+
35+
[Parameter()]
36+
[String] $EventLogName,
37+
38+
[Parameter()]
39+
[String] $EventSource,
40+
41+
[Parameter()]
42+
[Int32] $EventID = 1
43+
44+
)
45+
46+
#endregion
47+
48+
Begin {}
49+
50+
Process {
51+
52+
$ErrorActionPreference = "Continue"
53+
54+
if ($Messages.Length -gt 0) {
55+
try {
56+
foreach($m in $Messages) {
57+
if ($NoConsoleOut -eq $false) {
58+
switch ($Level) {
59+
'Error' {
60+
Write-Error $m -ErrorAction SilentlyContinue
61+
Write-Host ('{0}{1}' -f (" " * $Indent), $m) -ForegroundColor Red
62+
}
63+
'Warn' {
64+
Write-Warning $m
65+
}
66+
'Info' {
67+
Write-Host ('{0}{1}' -f (" " * $Indent), $m) -ForegroundColor $ForegroundColor
68+
}
69+
}
70+
}
71+
72+
if ($m.Trim().Length -gt 0) {
73+
$msg = '{0}{1} [{2}] : {3}' -f (" " * $Indent), (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Level.ToUpper(), $m
74+
75+
if ($Clobber) {
76+
$msg | Out-File -FilePath $Path -Force
77+
} else {
78+
$msg | Out-File -FilePath $Path -Append
79+
}
80+
}
81+
82+
if ($EventLogName) {
83+
84+
if (-not $EventSource) {
85+
$EventSource = ([IO.FileInfo] $MyInvocation.ScriptName).Name
86+
}
87+
88+
if(-not [Diagnostics.EventLog]::SourceExists($EventSource)) {
89+
[Diagnostics.EventLog]::CreateEventSource($EventSource, $EventLogName)
90+
}
91+
92+
$log = New-Object System.Diagnostics.EventLog
93+
$log.set_log($EventLogName)
94+
$log.set_source($EventSource)
95+
96+
switch ($Level) {
97+
"Error" { $log.WriteEntry($Message, 'Error', $EventID) }
98+
"Warn" { $log.WriteEntry($Message, 'Warning', $EventID) }
99+
"Info" { $log.WriteEntry($Message, 'Information', $EventID) }
100+
}
101+
}
102+
}
103+
}
104+
catch {
105+
throw "Failed to create log entry in: '$Path'. The error was: '$_'."
106+
}
107+
}
108+
}
109+
110+
End {}
111+
112+
<#
113+
.SYNOPSIS
114+
Writes logging information to screen and log file simultaneously.
115+
116+
.DESCRIPTION
117+
Writes logging information to screen and log file simultaneously. Supports multiple log levels.
118+
119+
.PARAMETER Messages
120+
The messages to be logged.
121+
122+
.PARAMETER Level
123+
The type of message to be logged.
124+
125+
.PARAMETER NoConsoleOut
126+
Specifies to not display the message to the console.
127+
128+
.PARAMETER ConsoleForeground
129+
Specifies what color the text should be be displayed on the console. Ignored when switch 'NoConsoleOut' is specified.
130+
131+
.PARAMETER Indent
132+
The number of spaces to indent the line in the log file.
133+
134+
.PARAMETER Path
135+
The log file path.
136+
137+
.PARAMETER Clobber
138+
Existing log file is deleted when this is specified.
139+
140+
.PARAMETER EventLogName
141+
The name of the system event log, e.g. 'Application'.
142+
143+
.PARAMETER EventSource
144+
The name to appear as the source attribute for the system event log entry. This is ignored unless 'EventLogName' is specified.
145+
146+
.PARAMETER EventID
147+
The ID to appear as the event ID attribute for the system event log entry. This is ignored unless 'EventLogName' is specified.
148+
149+
.EXAMPLE
150+
PS C:\> Write-Log -Message "It's all good!" -Path C:\MyLog.log -Clobber -EventLogName 'Application'
151+
152+
.EXAMPLE
153+
PS C:\> Write-Log -Message "Oops, not so good!" -Level Error -EventID 3 -Indent 2 -EventLogName 'Application' -EventSource "My Script"
154+
155+
.INPUTS
156+
System.String
157+
158+
.OUTPUTS
159+
No output.
160+
161+
.NOTES
162+
Revision History:
163+
2011-03-10 : Andy Arismendi - Created.
164+
#>
165+
}
166+
167+
function Create-Process() {
168+
param([string] $fileName, [string] $arguments)
169+
170+
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
171+
$pinfo.RedirectStandardError = $true
172+
$pinfo.RedirectStandardOutput = $true
173+
$pinfo.UseShellExecute = $false
174+
$pinfo.FileName = $fileName
175+
$pinfo.Arguments = $arguments
176+
177+
$p = New-Object System.Diagnostics.Process
178+
$p.StartInfo = $pinfo
179+
180+
return $p
181+
}
182+
183+
function HandlePublishError {
184+
185+
# Run NuGet Setup
186+
$setupTask = Start-Process PowerShell.exe "-ExecutionPolicy Unrestricted -File .\NuGetSetup.ps1 -Url $url" -Wait -PassThru
187+
188+
if ($setupTask.ExitCode -eq 0) {
189+
# Try to push package again
190+
$publishTask = Create-Process .\NuGet.exe ("push " + $_.Name + " -Source " + $url)
191+
$publishTask.Start() | Out-Null
192+
$publishTask.WaitForExit()
193+
194+
$output = ($publishTask.StandardOutput.ReadToEnd() -Split '[\r\n]') |? {$_}
195+
$error = (($publishTask.StandardError.ReadToEnd() -Split '[\r\n]') |? {$_})
196+
Write-Log $output
197+
Write-Log $error Error
198+
199+
if ($publishTask.ExitCode -eq 0) {
200+
$ExitCode = 0
201+
}
202+
}
203+
else {
204+
$ExitCode = 0
205+
}
206+
}
207+
208+
function Publish {
209+
210+
Write-Log " "
211+
Write-Log "Publishing package..." -ForegroundColor Green
212+
213+
# Get nuget config
214+
[xml]$nugetConfig = Get-Content .\NuGet.Config
215+
216+
$nugetConfig.configuration.packageSources.add | ForEach-Object {
217+
$url = $_.value
218+
219+
Write-Log "Repository Url: $url"
220+
Write-Log " "
221+
222+
Get-ChildItem *.nupkg | Where-Object { $_.Name.EndsWith(".symbols.nupkg") -eq $false } | ForEach-Object {
223+
224+
# Try to push package
225+
$task = Create-Process .\NuGet.exe ("push " + $_.Name + " -Source " + $url)
226+
$task.Start() | Out-Null
227+
$task.WaitForExit()
228+
229+
$output = ($task.StandardOutput.ReadToEnd() -Split '[\r\n]') |? {$_}
230+
$error = (($task.StandardError.ReadToEnd() -Split '[\r\n]') |? {$_})
231+
Write-Log $output
232+
Write-Log $error Error
233+
234+
if ($task.ExitCode -gt 0) {
235+
HandlePublishError
236+
}
237+
else {
238+
$ExitCode = 0
239+
}
240+
}
241+
}
242+
}
243+
244+
Write-Log " "
245+
Write-Log "NuGet Packager 2.0.2" -ForegroundColor Yellow
246+
247+
# Make sure the nuget executable is writable
248+
Set-ItemProperty NuGet.exe -Name IsReadOnly -Value $false
249+
250+
# Make sure the nupkg files are writeable and create backup
251+
if (Test-Path *.nupkg) {
252+
Set-ItemProperty *.nupkg -Name IsReadOnly -Value $false
253+
254+
Write-Log " "
255+
Write-Log "Creating backup..." -ForegroundColor Green
256+
257+
Get-ChildItem *.nupkg | ForEach-Object {
258+
Move-Item $_.Name ($_.Name + ".bak") -Force
259+
Write-Log ("Renamed " + $_.Name + " to " + $_.Name + ".bak")
260+
}
261+
}
262+
263+
Write-Log " "
264+
Write-Log "Updating NuGet..." -ForegroundColor Green
265+
Write-Log (Invoke-Command {.\NuGet.exe update -Self} -ErrorAction Stop)
266+
267+
Write-Log " "
268+
Write-Log "Creating package..." -ForegroundColor Green
269+
270+
# Create symbols package if any .pdb files are located in the lib folder
271+
If ((Get-ChildItem *.pdb -Path .\lib -Recurse).Count -gt 0) {
272+
Write-Log (Invoke-Command {.\NuGet.exe pack Package.nuspec -Symbol -Verbosity Detailed 2>&1})
273+
$ExitCode = $LASTEXITCODE
274+
}
275+
Else {
276+
Write-Log (Invoke-Command {.\NuGet.exe pack Package.nuspec -Verbosity Detailed 2>&1})
277+
$ExitCode = $LASTEXITCODE
278+
}
279+
280+
# Check if package should be published
281+
if ($Publish) {
282+
Publish
283+
}
284+
285+
Write-Log " "
286+
Write-Log "Exit Code: $ExitCode" -ForegroundColor Gray
287+
288+
$host.SetShouldExit($ExitCode)
289+
Exit $ExitCode

0 commit comments

Comments
 (0)