Skip to content

Instantly share code, notes, and snippets.

View baronfel's full-sized avatar

Chet Husk baronfel

View GitHub Profile
<?xml version="1.0" encoding="utf-16"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="ValidateSolutionConfiguration;ValidateToolsVersions;ValidateProjects" DefaultTargets="Build">
<PropertyGroup>
<MSBuildFileVersion>17.6.0.18004</MSBuildFileVersion>
<MSBuildSemanticVersion>17.6.0+61dd65684</MSBuildSemanticVersion>
<RoslynTargetsPath>C:\Program Files\dotnet\sdk\7.0.303\Roslyn</RoslynTargetsPath>
<VisualStudioVersion>17.0</VisualStudioVersion>
<_DirectorySolutionPropsFile>Directory.Solution.props</_DirectorySolutionPropsFile>
<_DirectorySolutionPropsBasePath />
<Configuration>Debug</Configuration>
@baronfel
baronfel / Directory.Build.targets
Last active May 23, 2023 20:53
Targets file to build multiple containers for a single project (or enable solution-level project management!)
<Project>
<PropertyGroup>
<!-- We have to build Publish AND PublishContainer because PublishContainer (and other
PublishProfile-delivered targets) don't have an explicit Publish dependency. -->
<_RequiredContainerPublishTargets>Publish;PublishContainer</_RequiredContainerPublishTargets>
</PropertyGroup>
<!-- Entrypoint, either from solution-level `/t:Containerize` or project-level `/t:Containerize` -->
<Target Name="Containerize" Condition="'$(EnableSdkContainerSupport)' == 'true'">
<!-- Strategy here is that we will figure out what proejct(s) to build the containerization targets(s) for
@baronfel
baronfel / Azure.Functions.Container.targets
Created May 2, 2023 15:36
Azure Functions Isolated dockerfile using SDK Containers
<Project>
<!-- Targets that replicate the behavior of the azure functions isolated dockerfile using the
SDK container tech -->
<Target Name="EnsureValidFunctionsTFM">
<PropertyGroup>
<_MinimumSupportedFunctionsTFM>6.0</_MinimumSupportedFunctionsTFM>
<_MaximumSupportedFunctionsTFM>7.0</_MaximumSupportedFunctionsTFM>
</PropertyGroup>
#r "System.Threading.Channels"
open System.Threading.Channels
open System.Threading
open System
open System.Threading.Tasks
open System.Threading
type Mailbox<'state, 'msg>(initialState, f, ctok) as this =
let c: Channel<'msg> = Channel.CreateUnbounded(UnboundedChannelOptions(SingleReader = true, SingleWriter = true))
@baronfel
baronfel / between.fsx
Last active January 23, 2023 02:33
Between Active Pattern
open System
[<return:Struct>]
let inline (|Between|_|) left right value =
if value > left && value < right then ValueSome () else ValueNone
let today = DateTime.Now
let yesterday = DateTime.Now.AddDays(-1.0)
let tomorrow = DateTime.Now.AddDays(1.0)
let twoDaysAgo = DateTime.Now.AddDays(-2.0)
@baronfel
baronfel / Blackjack.fsx
Created December 1, 2022 23:11
Blackjack kata
type Suit =
| Spades
| Clubs
| Diamonds
| Hearts
type Face =
| Two
| Three
| Four
@baronfel
baronfel / checking.fsx
Created October 13, 2022 18:33
Minimal FCS source checking
#r "FSharp.Compiler.Service"
open FSharp.Compiler.EditorServices
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Text
open System.IO
let fcsVersion =
System
.Reflection
.Assembly
@baronfel
baronfel / license-attribute.targets
Created October 9, 2022 23:31
MSBuild target to write license expressions to an assembly attribute
<Project>
<!-- Create a target that will assign the license information for a project to an attribute -->
<Target Name="AssignLicenseAttribute">
<!-- Only do this if the user is allowing assemblyinfo generation -->
<ItemGroup Condition="'$(GenerateAssemblyInfo)' == 'true'">
<!-- Only generate if the license is present and the user has requested this attribute -->
<AssemblyAttribute
Include="System.Reflection.AssemblyMetadataAttribute"
Condition="'$(GenerateLicenseExpressionAttribute)' == 'true' and '$(PackageLicenseExpression)' != ''">
<_Parameter1>LicenseExpression</_Parameter1>
@baronfel
baronfel / pack-help.sh
Last active August 5, 2022 16:30
Potential `dotnet pack` help output for nuspecs
➜ dotnet pack --help
Description:
Create NuGet packages out of .NET projects or Nuspec files.
Usage:
dotnet pack [<PROJECT | SOLUTION>...] [Project Packing Options]
dotnet pack <NUSPEC> [Nuspec Packing Options]
Arguments:
<PROJECT | SOLUTION> A project or solution file to operate on. If a file is not specified, the command will search the current directory for one.
@baronfel
baronfel / multitargeting-msbuild-targets.md
Last active August 3, 2022 19:23
changes made to seamlessly move to multitargeting

Multitargeting your MSBuild tasks and targets

Why would you multitarget?

For all practical purposes, you must multitarget. There is a huge chunk of the MSBuild ecosystem that's stuck on the .NET Framework build of MSBuild - everyone using tooling inside Visual Studio meets this criteria. If you don't support both Full and Core MSBuild distributions you're artificially cutting out your user base.

What does multitargeting mean?

For 'normal' .NET SDK projects, multitargeting means setting multiple TargetFrameworks in your project file. When you do this, builds will be triggered for both TFM, and the overall results can be packaged as a single artifact.