Skip to content

Commit 2f6dc63

Browse files
Ellerbachangularsenjosesimoes
authored
Support nanoFramework (#837)
Co-authored-by: Andreas Gullberg Larsen <[email protected]> Co-authored-by: José Simões <[email protected]>
1 parent 3bca803 commit 2f6dc63

File tree

445 files changed

+42754
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

445 files changed

+42754
-7
lines changed

Build/build-functions.psm1

+27-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ if ($msbuild) {
1010
$msbuild = join-path $msbuild 'MSBuild\Current\Bin\MSBuild.exe'
1111
}
1212

13+
import-module $PSScriptRoot\build-pack-nano-nugets.psm1
14+
1315
function Remove-ArtifactsDir {
1416
if (Test-Path $artifactsDir) {
1517
write-host -foreground blue "Clean up...`n"
@@ -25,7 +27,7 @@ function Update-GeneratedCode {
2527
write-host -foreground blue "Generate code...END`n"
2628
}
2729

28-
function Start-Build([boolean] $IncludeWindowsRuntimeComponent = $false) {
30+
function Start-Build([boolean] $IncludeWindowsRuntimeComponent = $false, [boolean] $IncludeNanoFramework = $false) {
2931
write-host -foreground blue "Start-Build...`n---"
3032

3133
$fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$testReportDir\UnitsNet.msbuild.log"
@@ -54,6 +56,22 @@ function Start-Build([boolean] $IncludeWindowsRuntimeComponent = $false) {
5456
if ($lastexitcode -ne 0) { exit 1 }
5557
}
5658

59+
if (-not $IncludeNanoFramework)
60+
{
61+
write-host -foreground yellow "Skipping .NET nanoFramework build."
62+
}
63+
else
64+
{
65+
$fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$testReportDir\UnitsNet.NanoFramework.msbuild.log"
66+
$appVeyorLoggerArg = if (Test-Path "$appVeyorLoggerDll") { "/logger:$appVeyorLoggerDll" } else { "" }
67+
68+
# msbuild does not auto-restore nugets for this project type
69+
& "nuget" restore "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln"
70+
# now build
71+
& "$msbuild" "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln" /verbosity:minimal /p:Configuration=Release $fileLoggerArg $appVeyorLoggerArg
72+
if ($lastexitcode -ne 0) { exit 1 }
73+
}
74+
5775
write-host -foreground blue "Start-Build...END`n"
5876
}
5977

@@ -115,6 +133,14 @@ function Start-PackNugets {
115133
& $nuget pack "$root\UnitsNet.WindowsRuntimeComponent\UnitsNet.WindowsRuntimeComponent.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir"
116134
}
117135

136+
if (-not $IncludeNanoFramework) {
137+
write-host -foreground yellow "Skipping nanoFramework nuget pack."
138+
} else {
139+
write-host -foreground yellow "nanoFramework project not yet supported by dotnet CLI, using nuget.exe instead"
140+
Build-NanoNugets
141+
}
142+
143+
118144
write-host -foreground blue "Pack nugets...END`n"
119145
}
120146

Build/build-pack-nano-nugets.psm1

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
$root = "$PSScriptRoot\.."
2+
$nugetOutDir = "$root\Artifacts\NuGet"
3+
$nuget = "$root\Tools\NuGet.exe"
4+
5+
function Build-NanoNugets {
6+
7+
& $nuget pack "$root\UnitsNet.NanoFramework\GeneratedCode\Temperature\UnitsNet.NanoFramework.Temperature.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir"
8+
9+
}
10+
11+
export-modulemember -function Build-NanoNugets

Build/build.ps1

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
some large, extra Visual Studio features to be installed.
1313
.EXAMPLE
1414
powershell ./build.ps1
15-
powershell ./build.ps1 -skipUWP
15+
powershell ./build.ps1 -IncludeWindowsRuntimeComponent -IncludeNanoFramework
1616
1717
.NOTES
1818
Author: Andreas Gullberg Larsen
1919
Last modified: Jan 21, 2018
2020
#>
2121
[CmdletBinding()]
2222
Param(
23-
[switch] $IncludeWindowsRuntimeComponent
23+
[switch] $IncludeWindowsRuntimeComponent,
24+
[switch] $IncludeNanoFramework
2425
)
2526

2627
remove-module build-functions -ErrorAction SilentlyContinue
@@ -31,7 +32,7 @@ try {
3132

3233
Remove-ArtifactsDir
3334
Update-GeneratedCode
34-
Start-Build -IncludeWindowsRuntimeComponent $IncludeWindowsRuntimeComponent
35+
Start-Build -IncludeWindowsRuntimeComponent $IncludeWindowsRuntimeComponent -IncludeNanoFramework $IncludeNanoFramework
3536
Start-Tests
3637
Start-PackNugets
3738
Compress-ArtifactsAsZip

Build/init.ps1

+24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ if (-not (Test-Path "$root/Tools/reportgenerator.exe")) {
1414
Write-Host -Foreground Green "Download dotnet-reportgenerator-globaltool...OK."
1515
}
1616

17+
# Install .NET nanoFramework build components
18+
19+
Write-Host "Installing .NET nanoFramework VS extension..."
20+
21+
[System.Net.WebClient]$webClient = New-Object System.Net.WebClient
22+
$webClient.UseDefaultCredentials = $true
23+
24+
$vsixFeedXml = Join-Path -Path $tempDir -ChildPath "vs-extension-feed.xml"
25+
$webClient.DownloadFile("http://vsixgallery.com/feed/author/nanoframework", $vsixFeedXml)
26+
[xml]$feedDetails = Get-Content $vsixFeedXml
27+
28+
$extensionUrl = $feedDetails.feed.entry[1].content.src
29+
$vsixPath = Join-Path -Path $tempDir -ChildPath "nf-extension.zip"
30+
$extensionVersion = $feedDetails.feed.entry[0].Vsix.Version
31+
$webClient.DownloadFile($extensionUrl,$vsixPath)
32+
Expand-Archive -LiteralPath $vsixPath -DestinationPath $tempDir\nf-extension\ | Write-Host
33+
34+
$VsWherePath = "${env:PROGRAMFILES(X86)}\Microsoft Visual Studio\Installer\vswhere.exe"
35+
$VsPath = $(&$VsWherePath -latest -property installationPath)
36+
$msbuildPath = Join-Path -Path $VsPath -ChildPath "\MSBuild"
37+
Copy-Item -Path "$tempDir\nf-extension\`$MSBuild\nanoFramework" -Destination $msbuildPath -Recurse
38+
39+
Write-Host "Installed VS extension v$extensionVersion"
40+
1741
# Cleanup
1842
[system.io.Directory]::Delete($tempDir, $true) | out-null
1943

CodeGen/CodeGen.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
14+
<PackageReference Include="NuGet.Protocol" Version="5.9.0" />
1415
<PackageReference Include="Serilog" Version="2.9.0" />
1516
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
1617
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.2.0-alpha.19174.3" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using CodeGen.JsonTypes;
5+
6+
namespace CodeGen.Generators.NanoFrameworkGen
7+
{
8+
class ProjectGenerator: GeneratorBase
9+
{
10+
private readonly Quantity _quantity;
11+
12+
public ProjectGenerator(Quantity quantity)
13+
{
14+
_quantity = quantity ?? throw new ArgumentNullException(nameof(quantity));
15+
}
16+
17+
public override string Generate()
18+
{
19+
Writer.WL($@"<?xml version=""1.0"" encoding=""utf-8""?>
20+
<Project ToolsVersion=""15.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
21+
<PropertyGroup Label=""Globals"">
22+
<NanoFrameworkProjectSystemPath>$(MSBuildToolsPath)..\..\..\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
23+
</PropertyGroup>
24+
<Import Project=""$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props"" Condition=""Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')"" />
25+
<PropertyGroup>
26+
<Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>
27+
<Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
28+
<ProjectTypeGuids>{{11A8DD76-328B-46DF-9F39-F559912D0360}};{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}</ProjectTypeGuids>
29+
<ProjectGuid>{{{Guid.NewGuid()}}}</ProjectGuid>
30+
<OutputType>Library</OutputType>
31+
<AppDesignerFolder>Properties</AppDesignerFolder>
32+
<FileAlignment>512</FileAlignment>
33+
<RootNamespace>UnitsNet</RootNamespace>
34+
<AssemblyName>UnitsNet.{_quantity.Name}</AssemblyName>
35+
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
36+
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
37+
</PropertyGroup>
38+
<Import Project=""$(NanoFrameworkProjectSystemPath)NFProjectSystem.props"" Condition=""Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')"" />
39+
<ItemGroup>
40+
<Compile Include=""..\Quantities\{_quantity.Name}.g.cs"" />
41+
<Compile Include=""..\Units\{_quantity.Name}Unit.g.cs"" />
42+
<Compile Include=""..\Properties\AssemblyInfo.cs"" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Reference Include=""mscorlib, Version={NanoFrameworkGenerator.MscorlibVersion}, Culture=neutral, PublicKeyToken=c07d481e9758c731"">
46+
<HintPath>..\packages\nanoFramework.CoreLibrary.{NanoFrameworkGenerator.MscorlibNuGetVersion}\lib\mscorlib.dll</HintPath>
47+
<Private>True</Private>
48+
<SpecificVersion>True</SpecificVersion>
49+
</Reference>");
50+
51+
if(NanoFrameworkGenerator.ProjectsRequiringMath.Contains(_quantity.Name))
52+
{
53+
Writer.WL($@"
54+
<Reference Include=""System.Math, Version={NanoFrameworkGenerator.MathVersion}, Culture=neutral, PublicKeyToken=c07d481e9758c731"">
55+
<HintPath>..\packages\nanoFramework.System.Math.{NanoFrameworkGenerator.MathNuGetVersion}\lib\System.Math.dll</HintPath>
56+
<Private>True</Private>
57+
<SpecificVersion>True</SpecificVersion>
58+
</Reference>");
59+
}
60+
61+
Writer.WL(@"
62+
</ItemGroup>
63+
<ItemGroup>
64+
<None Include=""packages.config"" />
65+
</ItemGroup>
66+
<Import Project=""$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets"" Condition=""Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')"" />
67+
<ProjectExtensions>
68+
<ProjectCapabilities>
69+
<ProjectConfigurationsDeclaredAsItems />
70+
</ProjectCapabilities>
71+
</ProjectExtensions>
72+
</Project>");
73+
74+
return Writer.ToString();
75+
}
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace CodeGen.Generators.NanoFrameworkGen
6+
{
7+
class PropertyGenerator : GeneratorBase
8+
{
9+
public override string Generate()
10+
{
11+
Writer.WL(GeneratedFileHeader);
12+
Writer.W(@"using System.Reflection;
13+
using System.Runtime.CompilerServices;
14+
using System.Runtime.InteropServices;
15+
16+
// General Information about an assembly is controlled through the following
17+
// set of attributes. Change these attribute values to modify the information
18+
// associated with an assembly.
19+
[assembly: AssemblyTitle(""CUnitsNet"")]
20+
[assembly: AssemblyDescription(""Get all the common units of measurement and the conversions between them. It is light-weight and thoroughly tested."")]
21+
[assembly: AssemblyConfiguration("""")]
22+
[assembly: AssemblyCompany(""Andreas Gullberg Larsen"")]
23+
[assembly: AssemblyProduct(""nanoFramework UnitsNet"")]
24+
[assembly: AssemblyCopyright(""Copyright 2013 Andreas Gullberg Larsen ([email protected])."")]
25+
[assembly: AssemblyTrademark("""")]
26+
[assembly: AssemblyCulture("""")]
27+
28+
// Setting ComVisible to false makes the types in this assembly not visible
29+
// to COM components. If you need to access a type in this assembly from
30+
// COM, set the ComVisible attribute to true on that type.
31+
[assembly: ComVisible(false)]
32+
33+
// Version information for an assembly consists of the following four values:
34+
//
35+
// Major Version
36+
// Minor Version
37+
// Build Number
38+
// Revision
39+
//
40+
// You can specify all the values or you can default the Build and Revision Numbers
41+
// by using the '*' as shown below:
42+
// [assembly: AssemblyVersion(""1.0.*"")]
43+
[assembly: AssemblyVersion(""1.0.0.0"")]
44+
[assembly: AssemblyFileVersion(""1.0.0.0"")]
45+
46+
//////////////////////////////////////////////////
47+
// This assembly doens't require native support //
48+
[assembly: AssemblyNativeVersion(""0.0.0.0"")]
49+
//////////////////////////////////////////////////
50+
");
51+
return Writer.ToString();
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)