Skip to content

Commit 92e8b7a

Browse files
committed
SourceOnlyExample
1 parent 7387438 commit 92e8b7a

File tree

8 files changed

+564
-0
lines changed

8 files changed

+564
-0
lines changed

SourceOnlyExample/.gitignore

Lines changed: 484 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Helpers
2+
{
3+
internal class Class1
4+
{
5+
public static void SayHello() => global::System.Console.WriteLine("Hello!");
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<Nullable>disable</Nullable>
7+
<NuSpecFile>SourceOnlyExample.nuspec</NuSpecFile>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>SourceOnlyExample</id>
5+
<version>1.0.0</version>
6+
<developmentDependency>true</developmentDependency>
7+
<authors>Andrew Lock</authors>
8+
<license type="expression">MIT</license>
9+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
10+
<projectUrl>https://andrewlock.net/creating-source-only-nuget-packages/</projectUrl>
11+
<description>An example source-code only package</description>
12+
<tags>source compiletime</tags>
13+
</metadata>
14+
<files>
15+
<!--
16+
The files are included twice:
17+
As contentFiles (for PackageReferences)
18+
As content (for packages.config).
19+
-->
20+
<file src="*.cs" target="contentFiles/cs/netstandard2.0/SourceOnlyExample/"/>
21+
<file src="*.cs" target="content/cs/netstandard2.0/SourceOnlyExample/"/>
22+
23+
<!-- Hide content files from Visual Studio solution explorer -->
24+
<file src="SourceOnlyExample.props" target="build/SourceOnlyExample.props" />
25+
</files>
26+
</package>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project>
2+
<!--
3+
Hide content files from Visual Studio solution explorer. Adapted from:
4+
https://til.cazzulino.com/dotnet/nuget/hide-contentfiles-from-your-nuget-packages
5+
-->
6+
<ItemGroup>
7+
<Compile Update="@(Compile)">
8+
<Visible Condition="'%(NuGetItemType)' == 'Compile' and '%(NuGetPackageId)' == 'SourceOnlyExample'">false</Visible>
9+
</Compile>
10+
</ItemGroup>
11+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Helpers.Class1.SayHello();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="SourceOnlyExample" Version="1.0.0">
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
<PrivateAssets>all</PrivateAssets>
14+
</PackageReference>
15+
</ItemGroup>
16+
17+
</Project>

SourceOnlyExample/build.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$ErrorActionPreference = "Stop"
2+
dotnet build -c Release ./SourceOnlyExample/SourceOnlyExample.csproj
3+
dotnet pack -c Release ./SourceOnlyExample/SourceOnlyExample.csproj
4+
rm -r -Force ./packages/*
5+
dotnet remove ./TestApp/TestApp.csproj package SourceOnlyExample
6+
dotnet add ./TestApp/TestApp.csproj package SourceOnlyExample --package-directory ./packages --source ./SourceOnlyExample/bin/Release/
7+
dotnet build ./TestApp/TestApp.csproj --packages ./packages
8+
dotnet run --no-build --project ./TestApp/TestApp.csproj

0 commit comments

Comments
 (0)