Skip to content
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

NiceIO as a source-only package :D #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NiceIO.PackageTest/Extension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AnotherNamespace;

partial class NPath
{
public static NPath AnotherStatic => new("a/b/c");
}
12 changes: 12 additions & 0 deletions NiceIO.PackageTest/NiceIO.PackageTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PreprocessorValue Include="NICEIO_NAMESPACE" Value="AnotherNamespace" Visible="false" />
<PackageReference Include="NiceIO" Version="1.0.0" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions NiceIO.PackageTest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var path = AnotherNamespace.NPath.AnotherStatic.Combine("file.txt");
Console.WriteLine($"Path is {path}");
5 changes: 5 additions & 0 deletions NiceIO.PackageTest/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<configuration>
<config>
<add key="globalPackagesFolder" value="packages"/>
</config>
</configuration>
5 changes: 5 additions & 0 deletions NiceIO.PackageTest/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dotnet pack .. -p:NuspecFile=NiceIO.nuspec
dotnet add package NiceIO --source ..\bin\release --package-directory packages
if ((dotnet run) -ne 'Path is a/b/c/file.txt') { throw 'it broke' }
''
'Everything is shiny'
20 changes: 18 additions & 2 deletions NiceIO.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9</LangVersion>
Expand All @@ -8,4 +8,20 @@
<ItemGroup>
<Compile Include="NiceIO.cs"/>
</ItemGroup>
</Project>

<!-- macro-ize the namespace, and make class partial so package users can add statics -->
<!-- usage: `dotnet pack -p:NuspecFile=NiceIO.nuspec` -->

<Target Name="PrePack" BeforeTargets="GenerateNuspec"> <!-- we're not actually using the generated nuspec, but this is a convenient spot to generate the .pp -->
<WriteLinesToFile
File="obj/pack/NiceIO.cs.pp"
Lines="$(
[System.IO.File]::ReadAllText('NiceIO.cs')
.Replace('namespace NiceIO','namespace $NICEIO_NAMESPACE$')
.Replace('NiceIO.','$NICEIO_NAMESPACE$.')
.Replace('class NPath','partial class NPath')
)"
Overwrite="true">
</WriteLinesToFile>
</Target>
</Project>
22 changes: 22 additions & 0 deletions NiceIO.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- this needs to be done as a nuspec rather than generated from the csproj because
generation will mark the .pp in the generated .nuspec as "buildAction=none", which
prevents the project trying to compile with it. -->
<package xmlns="http://schemas.microsoft.com/packaging/2016/06/nuspec.xsd">
<metadata>
<id>NiceIO</id>
<version>1.0.0</version>
<title>NiceIO</title>
<description>For when you've had to use System.IO one time too many.</description>
<authors>Lucas Meijer</authors>
<repository type="git" url="https://github.com/lucasmeijer/NiceIO" />
<license type="expression">MIT</license>
<readme>README.md</readme>
<contentFiles>
</contentFiles>
</metadata>
<files>
<file src="README.md" />
<file src="obj/pack/NiceIO.cs.pp" target="contentFiles/cs/netstandard2.0/NiceIO.cs.pp" />
</files>
</package>
4 changes: 3 additions & 1 deletion NiceIO.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand All @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NiceIO", "NiceIO.csproj", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NiceIO.Tests", "NiceIO.Tests\NiceIO.Tests.csproj", "{AC76E796-A1C5-44D7-84F5-88BFD0908767}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NiceIO.PackageTest", "NiceIO.PackageTest\NiceIO.PackageTest.csproj", "{7BA16958-FDAE-411E-9EE2-81563B3D4A69}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down