Skip to content

Commit 19e694d

Browse files
authored
Migrate tools to .NET Core (dotnet#697)
1 parent 9dbad7a commit 19e694d

24 files changed

+528
-522
lines changed

All.sln

+66-75
Large diffs are not rendered by default.

build.cmd

+2-134
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,4 @@
11
@ECHO OFF
22
PUSHD %~dp0
3-
4-
SETLOCAL
5-
SETLOCAL ENABLEDELAYEDEXPANSION
6-
7-
:Loop
8-
if [%1]==[] GOTO Begin
9-
10-
if /I [%1]==[Debug] (
11-
SET Configuration=%1
12-
GOTO Next
13-
)
14-
15-
if /I [%1]==[Release] (
16-
SET Configuration=%1
17-
GOTO Next
18-
)
19-
20-
if /I [%1]==[PROD] (
21-
SET Environment=PROD
22-
GOTO Next
23-
)
24-
25-
if /I [%1]==[raw] (
26-
SET SkipTemplate=true
27-
GOTO Next
28-
)
29-
30-
if /I [%1]==[template] (
31-
SET UpdateTemplate=%1
32-
GOTO Next
33-
)
34-
35-
:Next
36-
SHIFT /1
37-
GOTO Loop
38-
39-
:Begin
40-
:: Check if dotnet cli exists globally
41-
WHERE dotnet >NUL
42-
IF NOT [!ERRORLEVEL!]==[0] (
43-
ECHO ERROR: dotnet CLI is not successfully configured.
44-
ECHO ERROR: Please follow https://www.microsoft.com/net/core to install .NET Core.
45-
GOTO Exit
46-
)
47-
:: Check if nuget.exe exists globally
48-
SET CachedNuget=%LocalAppData%\NuGet\NuGet.exe
49-
IF NOT EXIST "%CachedNuget%" (
50-
ECHO Downloading NuGet.exe...
51-
powershell -NoProfile -ExecutionPolicy UnRestricted -Command "$ProgressPreference = 'SilentlyContinue'; [Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultCredentials; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile '%CachedNuget%'"
52-
)
53-
54-
:: Set environment variable
55-
SET BuildProj=%~dp0All.sln
56-
IF [%Configuration%]==[] (
57-
SET Configuration=Release
58-
)
59-
60-
IF /I [%Environment%]==[PROD] (
61-
ECHO Updating version for PROD environment
62-
CALL UpdateVersion.cmd
63-
64-
IF NOT [!ERRORLEVEL!]==[0] (
65-
ECHO ERROR: Error occurs when updating version
66-
GOTO Exit
67-
)
68-
)
69-
70-
IF /I [%UpdateTemplate%]==[template] (
71-
CALL :UpdateTemplate
72-
GOTO Exit
73-
)
74-
75-
IF /I [%SkipTemplate%]==[true] (
76-
ECHO Skip updating template
77-
GOTO RestorePackage
78-
)
79-
80-
:: Update template before build
81-
:UpdateTemplate
82-
ECHO Updating template
83-
CALL UpdateTemplate.cmd
84-
IF NOT [!ERRORLEVEL!]==[0] (
85-
ECHO ERROR: Error occurs when updating template
86-
GOTO Exit
87-
)
88-
89-
:RestorePackage
90-
FOR /D %%x IN ("src", "test") DO (
91-
PUSHD %%x
92-
dotnet restore
93-
POPD
94-
)
95-
96-
:BuildProject
97-
ECHO Building project
98-
FOR /f %%g IN ('DIR /b "src"') DO (
99-
dotnet build src\%%g -c %Configuration% -f net452
100-
XCOPY /ey src\%%g\bin\%Configuration%\net452\win7-x64\** target\%Configuration%\%%g\
101-
)
102-
103-
:RunUnitTests
104-
ECHO Run all unit tests
105-
FOR /f %%g IN ('DIR /b "test"') DO (
106-
IF NOT %%g==Shared (
107-
IF NOT %%g==docfx.E2E.Tests (
108-
dotnet test test\%%g
109-
)
110-
)
111-
)
112-
113-
:GenerateArtifacts
114-
ECHO pack projct nuget package
115-
FOR /f %%g IN ('DIR /b "src"') DO (
116-
dotnet pack src\%%g -c %Configuration% -o artifacts\%Configuration%
117-
)
118-
119-
ECHO pack docfx.conosle
120-
ECHO XCOPY /ey target\%Configuration%\docfx\*.dll src\nuspec\docfx.console\tools\
121-
XCOPY /ey target\%Configuration%\docfx\*.dll src\nuspec\docfx.console\tools\
122-
XCOPY /ey target\%Configuration%\docfx\*.exe src\nuspec\docfx.console\tools\
123-
XCOPY /ey target\%Configuration%\docfx\*.exe.config src\nuspec\docfx.console\tools\
124-
SET versionFile=TEMP/version.txt
125-
IF EXIST %versionFile% (
126-
SET /p versions=<%versionFile%
127-
SET version=!versions:~1!
128-
) ELSE (
129-
SET version=1.0.0
130-
)
131-
%CachedNuget% pack src\nuspec\docfx.console\docfx.console.nuspec -Version %version% -OutputDirectory artifacts\%Configuration%
132-
133-
:Exit
134-
POPD
135-
ECHO.
136-
EXIT /B %ERRORLEVEL%
3+
PowerShell -NoProfile -ExecutionPolicy Bypass -Command ".\build.ps1 %*; exit $LastExitCode;"
4+
POPD

build.ps1

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
param(
2+
[string] $configuration = "Release",
3+
[switch] $raw = $false,
4+
[switch] $prod = $false
5+
)
6+
7+
################################################################################################
8+
# Usage:
9+
# Run build.ps1
10+
# [-configuration Configuration]: Default to be Release
11+
# [-raw]: If it's set, the build process will skip updating template
12+
# [-prod]: If it's set, the build process will update version
13+
################################################################################################
14+
15+
$ErrorActionPreference = 'Stop'
16+
$scriptPath = $MyInvocation.MyCommand.Path
17+
$scriptHome = Split-Path $scriptPath
18+
19+
Push-Location $scriptHome
20+
21+
# Check if dotnet cli exists globally
22+
if ((Get-Command "dotnet" -ErrorAction SilentlyContinue) -eq $null)
23+
{
24+
Write-Host "dotnet CLI is not successfully configured."
25+
Write-Host "Please follow https://www.microsoft.com/net/core to install .NET Core."
26+
Exit 1
27+
}
28+
29+
# Check if nuget.exe exists
30+
$nuget = "$env:APPDATA\Nuget\Nuget.exe"
31+
if (-not(Test-Path $nuget))
32+
{
33+
Write-Host "Downloading NuGet.exe..."
34+
$ProgressPreference = 'SilentlyContinue'
35+
[Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultCredentials
36+
Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile $nuget
37+
}
38+
39+
if ($raw -eq $false)
40+
{
41+
& ".\UpdateTemplate.cmd"
42+
if ($lastexitcode -ne 0) { Write-Error "Update templte error, exit code: $lastexitcode"; Pop-Location }
43+
}
44+
else
45+
{
46+
Write-Host "Skip updating template"
47+
}
48+
49+
if ($prod -eq $true)
50+
{
51+
& ".\UpdateVersion.cmd"
52+
if ($lastexitcode -ne 0) { Write-Error "Update version error, exit code: $lastexitcode"; Pop-Location }
53+
}
54+
55+
# Restore package
56+
Write-Host "Start to restore package"
57+
foreach ($folder in @("src", "test", "tools"))
58+
{
59+
Push-Location $folder
60+
& dotnet restore
61+
if ($lastexitcode -ne 0) { Write-Error "dotnet restore $folder error, exit code: $lastexitcode"; Pop-Location }
62+
Pop-Location
63+
}
64+
65+
# Build project
66+
Write-Host "Start to build project"
67+
foreach ($folder in (dir "src"))
68+
{
69+
if (Test-Path (Join-Path $folder.FullName "project.json")) {
70+
& dotnet publish $folder.FullName -o target\$configuration\$folder
71+
if ($lastexitcode -ne 0) { Write-Error "dotnet build $folder error, exit code: $lastexitcode"; Pop-Location }
72+
}
73+
}
74+
75+
# Run unit test cases
76+
Write-Host "Start to run unit test"
77+
foreach ($folder in (dir "test"))
78+
{
79+
if ((Test-Path (Join-Path $folder.FullName "project.json")) -and ($folder.Name -ne "Shared") -and ($folder.Name -ne "docfx.E2E.Tests"))
80+
{
81+
& dotnet test test\$folder
82+
if ($lastexitcode -ne 0) { Write-Error "dotnet test $folder error, exit code: $lastexitcode"; Pop-Location }
83+
}
84+
}
85+
86+
# Build tools
87+
Write-Host "Build tools"
88+
foreach ($folder in (dir "tools"))
89+
{
90+
if (Test-Path (Join-Path $folder.FullName "project.json"))
91+
{
92+
& dotnet publish $folder.FullName -o target\$configuration\$folder
93+
if ($lastexitcode -ne 0) { Write-Error "dotnet build $folder error, exit code: $lastexitcode"; Pop-Location }
94+
}
95+
}
96+
97+
# Pack artifacts
98+
Write-Host "Publish artifacts"
99+
foreach ($folder in (dir "src"))
100+
{
101+
if (Test-Path (Join-Path $folder.FullName "project.json"))
102+
{
103+
& dotnet pack $folder.FullName -c $configuration -o artifacts\$configuration
104+
if ($lastexitcode -ne 0) { Write-Error "dotnet pack $folder error, exit code: $lastexitcode"; Pop-Location }
105+
}
106+
}
107+
108+
# Pack docfx.console
109+
Copy-Item -Path "target\$configuration\docfx\*.dll" -Destination "src\nuspec\docfx.console\tools\"
110+
Copy-Item -Path "target\$configuration\docfx\*.exe" -Destination "src\nuspec\docfx.console\tools\"
111+
Copy-Item -Path "target\$configuration\docfx\*.exe.config" -Destination "src\nuspec\docfx.console\tools\"
112+
113+
$version = 1.0.0
114+
if (Test-Path "TEMP/version.txt")
115+
{
116+
$version = cat "TEMP/version.txt"
117+
$version = $version.Substring(1)
118+
}
119+
& $nuget pack "src\nuspec\docfx.console\docfx.console.nuspec" -Version $version -OutputDirectory artifacts\$configuration
120+
if ($lastexitcode -ne 0) { Write-Error "nuget pack docfx.console error, exit code: $lastexitcode"; Pop-Location; Pop-Location }
121+
122+
Write-Host "Complete."
123+
Pop-Location

tools/AzureMarkdownRewriterTool/AzureMarkdownRewriterTool.csproj

-70
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>74e13283-c24b-49a1-910b-502505995565</ProjectGuid>
10+
<RootNamespace>AzureMarkdownRewriterTool</RootNamespace>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
13+
</PropertyGroup>
14+
15+
<PropertyGroup>
16+
<SchemaVersion>2.0</SchemaVersion>
17+
</PropertyGroup>
18+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
19+
</Project>

tools/AzureMarkdownRewriterTool/packages.config

-5
This file was deleted.

0 commit comments

Comments
 (0)