Skip to content

Instantly share code, notes, and snippets.

View mgnslndh's full-sized avatar

Magnus Lindhe mgnslndh

View GitHub Profile
@mgnslndh
mgnslndh / ArgumentAliases.cs
Created May 12, 2025 11:54
GitLab Parallel Jobs
using Cake.Core;
namespace Custom.Cake.Aliases;
public static class ArgumentAliases
{
public static bool TryGetArgumentInt32(this ICakeContext context, string argumentName, out int value)
{
if (context.Arguments.HasArgument(argumentName))
{
@mgnslndh
mgnslndh / Block.targets
Created March 26, 2025 07:17
Block ProjectReference?
<ItemGroup>
<BlockedProjects Include="Test.SkiaSharp;DeniedProject2;DeniedProject3" />
</ItemGroup>
<Target Name="CheckBlockedProjectReferences" BeforeTargets="Build">
<Message Text="--> %(ProjectReference.Filename)" Importance="high"/>
<Message Text="Blocked: @(ProjectReference->WithMetadataValue('Filename', '%(BlockedProjects.Identity)'))" Importance="high"/>
<Error Text="The project '@(ProjectReference)' references a blocked project!"
Condition="'@(ProjectReference->WithMetadataValue('Filename', '%(BlockedProjects.Identity)'))' != ''" />
</Target>
@mgnslndh
mgnslndh / PointerTriggerBehavior.cs
Created August 18, 2023 14:23
This is an Avalonia behavior that lets you assign actions that will be executed when a pointer is pressed and/or released.
using Avalonia;
using Avalonia.Input;
using Avalonia.Xaml.Interactions.Events;
using Avalonia.Xaml.Interactivity;
namespace Avalonia.Xaml.Interactions
{
public class PointerTriggerBehavior : PointerEventsBehavior
{
/// <summary>
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Try.Try.Try
{
public abstract record Try<TSuccess, TFailure>
@mgnslndh
mgnslndh / Notes.md
Created January 13, 2022 08:14
NuGet Packaging

NuGet Packaging

Runtimes

When consuming a NuGet package with runtime libraries they will not be copied to the output directory if the consuming assembly is itself a library. It needs to be an executable.

Also note that class libraries don't have a host, hence don't have a RID. Therefore you may not see the runtime dlls. You need to make sure your test project that uses the package is something that has a host & entry point, like a console app.

Source.

<Project>
<Target Name="_DeleteFilesFromOutputDirectory" AfterTargets="CopyFilesToOutputDirectory">
<!-- Delete files that are not needed -->
<ItemGroup>
<!-- Satellite Assemblies -->
<FilesToDelete Include="$(OutDir)\**\*.resources.dll" />
</ItemGroup>
<Delete Files="@(FilesToDelete)" />
@mgnslndh
mgnslndh / BuildSecrets.targets
Created October 27, 2020 13:14
Build Secrets
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SomethingPropsDirectory>$(LOCALAPPDATA)\Something\</SomethingPropsDirectory>
<SomethingPropsFilePath>$(SomethingPropsDirectory)\Something.Build.props</SomethingPropsFilePath>
</PropertyGroup>
<Import Project="$(SomethingPropsFilePath)" Condition="Exists('$(SomethingPropsFilePath)')" />
<Target Name="GenerateBuildSecrets" BeforeTargets="CoreCompile">