Skip to content

XP One nuget per quantity #1181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
86 changes: 86 additions & 0 deletions CodeGen/Generators/UnitsNetGen/ProjectGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using CodeGen.Helpers;
using CodeGen.JsonTypes;

namespace CodeGen.Generators.UnitsNetGen
{
internal class ProjectGenerator : GeneratorBase
{
private readonly Quantity _quantity;

public ProjectGenerator(Quantity quantity)
{
_quantity = quantity ?? throw new ArgumentNullException(nameof(quantity));
}

public string Generate()
{
Writer.WL($@"<Project Sdk=""Microsoft.NET.Sdk"">

<!-- NuGet properties -->
<PropertyGroup>
<PackageId>UnitsNet.Duration</PackageId>
<Version>5.0.0-rc008</Version>
<Authors>Andreas Gullberg Larsen</Authors>
<Title>Units.NET {_quantity.Name}</Title>
<Description>Adds {_quantity.Name} units for Units.NET.</Description>
<Copyright>Copyright 2013 Andreas Gullberg Larsen ([email protected]).</Copyright>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RepositoryUrl>https://github.com/angularsen/UnitsNet</RepositoryUrl>
<PackageIcon>logo-32.png</PackageIcon>
<PackageIconUrl>https://raw.githubusercontent.com/angularsen/UnitsNet/ce85185429be345d77eb2ce09c99d59cc9ab8aed/Docs/Images/logo-32.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/angularsen/UnitsNet</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageTags>{_quantity.Name.ToLower()} unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<!-- Assembly and msbuild properties -->
<PropertyGroup>
<AssemblyVersion>5.0.0.0</AssemblyVersion> <!-- Should reflect major part of Version -->
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<RootNamespace>UnitsNet</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<ProjectGuid>{HashGuid.ToHashGuid(_quantity.Name):B}</ProjectGuid>
</PropertyGroup>

<!-- SourceLink -->
<PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<!-- Strong name signing -->
<PropertyGroup>
<AssemblyOriginatorKeyFile>../../UnitsNet.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<SignAssembly>true</SignAssembly>
<AssemblyName>UnitsNet.{_quantity.Name}</AssemblyName>
</PropertyGroup>

<!-- NuGet references that work for all TargetFrameworks, both signed and unsigned. -->
<ItemGroup>
<PackageReference Include=""Microsoft.SourceLink.GitHub"" Version=""1.1.1"" PrivateAssets=""All"" />
<!-- <PackageReference Include=""UnitsNet.Core"" Version="""" />-->
</ItemGroup>

<!-- Project references that replace nuget dependencies while building. -->
<ItemGroup>
<ProjectReference Include=""..\..\UnitsNet.Core\UnitsNet.Core.csproj"" />
</ItemGroup>

<!-- Files to include in nuget package -->
<ItemGroup>
<None Include=""../../Docs/Images/logo-32.png"" Pack=""true"" PackagePath=""/"" />
<None Include=""../../README.md"" Pack=""true"" PackagePath=""/"" />
</ItemGroup>

</Project>");

return Writer.ToString();
}
}
}
3 changes: 3 additions & 0 deletions CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ private void GenerateStaticProperties()
/// <inheritdoc cref=""IQuantity.QuantityInfo""/>
public static QuantityInfo<{_unitEnumName}> Info {{ get; }}

/// <inheritdoc cref=""IQuantity.QuantityInfo""/>
static QuantityInfo IQuantity.Info => Info;

/// <summary>
/// The <see cref=""BaseDimensions"" /> of this quantity.
/// </summary>
Expand Down
64 changes: 64 additions & 0 deletions CodeGen/Generators/UnitsNetGen/SolutionGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Text;
using CodeGen.Helpers;
using CodeGen.JsonTypes;

namespace CodeGen.Generators.UnitsNetGen
{
internal class SolutionGenerator : GeneratorBase
{
private readonly Quantity[] _quantities;
private readonly Guid _globalGuid = new("71d2836c-ed62-4b76-ba38-e15badcca916"); // Randomly generated guids.
private readonly Guid _solutionGuid = new("1f322b1f-1612-4e69-a31f-cb46bf87ec3e");

public SolutionGenerator(Quantity[] quantities)
{
_quantities = quantities;
}

public string Generate()
{
StringBuilder sb = new();
Writer.WL($@"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29609.76
MinimumVisualStudioVersion = 10.0.40219.1");

foreach (var quantity in _quantities)
{
var projectGuid = HashGuid.ToHashGuid(quantity.Name);
var projectName = $"UnitsNet.{quantity.Name}";
Writer.WL($@"
Project(""{_globalGuid:B}"") = ""{projectName}"", ""UnitsNet.Modular\{projectName}\{projectName}.csproj"", ""{projectGuid:B}""
EndProject");
sb.Append($"{{{projectGuid}}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n");
sb.Append($"{{{projectGuid}}}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n");
sb.Append($"{{{projectGuid}}}.Debug|Any CPU.Deploy.0 = Debug|Any CPU\r\n");
sb.Append($"{{{projectGuid}}}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n");
sb.Append($"{{{projectGuid}}}.Release|Any CPU.Build.0 = Release|Any CPU\r\n");
sb.Append($"{{{projectGuid}}}.Release|Any CPU.Deploy.0 = Release|Any CPU\r\n");
}

Writer.WL(@"Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution");

Writer.WL(sb.ToString());

Writer.WL($@" EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {_solutionGuid:B}
EndGlobalSection
EndGlobal
");
return Writer.ToString();
}
}
}
86 changes: 86 additions & 0 deletions CodeGen/Generators/UnitsNetModularGen/ProjectGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using CodeGen.Helpers;
using CodeGen.JsonTypes;

namespace CodeGen.Generators.UnitsNetModularGen
{
internal class ProjectGenerator : GeneratorBase
{
private readonly Quantity _quantity;

public ProjectGenerator(Quantity quantity)
{
_quantity = quantity ?? throw new ArgumentNullException(nameof(quantity));
}

public string Generate()
{
Writer.WL($@"<Project Sdk=""Microsoft.NET.Sdk"">

<!-- NuGet properties -->
<PropertyGroup>
<PackageId>UnitsNet.Duration</PackageId>
<Version>5.0.0-rc008</Version>
<Authors>Andreas Gullberg Larsen</Authors>
<Title>Units.NET {_quantity.Name}</Title>
<Description>Adds {_quantity.Name} units for Units.NET.</Description>
<Copyright>Copyright 2013 Andreas Gullberg Larsen ([email protected]).</Copyright>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RepositoryUrl>https://github.com/angularsen/UnitsNet</RepositoryUrl>
<PackageIcon>logo-32.png</PackageIcon>
<PackageIconUrl>https://raw.githubusercontent.com/angularsen/UnitsNet/ce85185429be345d77eb2ce09c99d59cc9ab8aed/Docs/Images/logo-32.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/angularsen/UnitsNet</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageTags>{_quantity.Name.ToLower()} unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<!-- Assembly and msbuild properties -->
<PropertyGroup>
<AssemblyVersion>5.0.0.0</AssemblyVersion> <!-- Should reflect major part of Version -->
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<RootNamespace>UnitsNet</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<ProjectGuid>{HashGuid.ToHashGuid(_quantity.Name):B}</ProjectGuid>
</PropertyGroup>

<!-- SourceLink -->
<PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<!-- Strong name signing -->
<PropertyGroup>
<AssemblyOriginatorKeyFile>../../UnitsNet.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<SignAssembly>true</SignAssembly>
<AssemblyName>UnitsNet.{_quantity.Name}</AssemblyName>
</PropertyGroup>

<!-- NuGet references that work for all TargetFrameworks, both signed and unsigned. -->
<ItemGroup>
<PackageReference Include=""Microsoft.SourceLink.GitHub"" Version=""1.1.1"" PrivateAssets=""All"" />
<!-- <PackageReference Include=""UnitsNet.Core"" Version="""" />-->
</ItemGroup>

<!-- Project references that replace nuget dependencies while building. -->
<ItemGroup>
<ProjectReference Include=""..\..\..\UnitsNet.Core\UnitsNet.Core.csproj"" />
</ItemGroup>

<!-- Files to include in nuget package -->
<ItemGroup>
<None Include=""../../../Docs/Images/logo-32.png"" Pack=""true"" PackagePath=""/"" />
<None Include=""../../../README.md"" Pack=""true"" PackagePath=""/"" />
</ItemGroup>

</Project>");

return Writer.ToString();
}
}
}
Loading