Skip to content

Build .NET SDK 3.1.103 for FreeBSD

Jason Pugsley edited this page May 6, 2020 · 2 revisions

At the time of writing this guide, .NET Core 3.1 on FreeBSD does not yet exist as a package download from a trusted location. To work around this issue, this guide provides the steps to allow you to build your own SDK directly from trusted sources. I have provided an SDK that is needed to do the build, but after following the steps, you will end up with your own SDK build from source.

There are a small number of code and config changes required to build the SDK and I have provided them in diff format here to make it easy to see what has been changed from the offical sources.

I would recommend doing the build on a fresh VM. A 50GB HDD, 8GB RAM and as many CPU cores as you can provide will speed up the build. It will need to be connected to the internet so that additional packages can be downloaded as the build progresses. I would also recommend you use FreeBSD 11.3 so that the resulting SDK can also work on FreeBSD 12.1

I guess I'm hoping that someone who is already trusted in the community can follow the build process, package up the resulting output and make it available somewhere official for the rest of the FreeBSD community. At some future point, it should be possible to download an installer from Microsoft just like all the other supported platforms.

The Build Steps

The steps assume you have created a user called build with a home directory /home/build The build user will also need to be able to run sudo

Download the seed SDK

.NET SDK 3.1.103 can be built with SDK 3.1.100. Download it from OneDrive and save to /home/build

Install FreeBSD packages for building

These packages are required to build the SDK.

$ sudo pkg install libunwind lttng-ust icu libinotify krb5 openssl cmake bash python git llvm

Additional Setup

Scripts in the installer repo are hard coded to use the path /bin/bash

$ sudo ln -s /usr/local/bin/bash /bin/bash

Set the timezone to UTC, otherwise there are some issues after extracting NuGet packages in the aspnetcore repo.

$ sudo tzsetup

We will be creating NuGet packages that are needed by subsequent repos so we'll store them in a directory called nupkg

We'll put all our repos under src

$ mkdir src nupkg
$ cd src
$ git clone https://github.com/dotnet/coreclr.git
$ git clone https://github.com/dotnet/corefx.git
$ git clone https://github.com/dotnet/core-setup.git
$ git clone https://github.com/dotnet/aspnetcore.git
$ git clone https://github.com/dotnet/installer.git

CoreCLR

$ cd coreclr
$ git checkout c5d3d752260383fbed72ba2b4d86d82fea673c76
$ mkdir .dotnet
$ tar xf $HOME/dotnet-sdk-3.1.100-freebsd-x64.tar.gz -C .dotnet/
$ ./build.sh -x64 -release -skiptests -stripsymbols /p:OfficialBuildId=20200218.3 /p:ContinuousIntegrationBuild=true /p:PortableBuild=true
$ cp bin/Product/FreeBSD.x64.Release/.nuget/pkg/*.nupkg $HOME/nupkg/

CoreFX

$ cd ../corefx
$ git checkout 8a3ffed558ddf943c1efa87d693227722d6af094
$ mkdir -p artifacts/bin/testhost/netcoreapp-FreeBSD-Release-x64
$ mkdir .dotnet
$ tar xf $HOME/dotnet-sdk-3.1.100-freebsd-x64.tar.gz -C .dotnet/

Required Changes

diff --git a/NuGet.config b/NuGet.config
index e105915bd6..62bca5705f 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -16,6 +16,7 @@
     <add key="dotnet3.1" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1/nuget/v3/index.json" />
     <add key="dotnet3.1-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1-transport/nuget/v3/index.json" />
     <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
+    <add key="local" value="/home/build/nupkg" />
   </packageSources>
   <disabledPackageSources>
     <clear />
diff --git a/eng/Versions.props b/eng/Versions.props
index f31d652218..1889bd9748 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -16,6 +16,7 @@
     <!-- Opt-in repo features -->
     <UsingToolMicrosoftNetCompilers>true</UsingToolMicrosoftNetCompilers>
     <UsingToolIbcOptimization>true</UsingToolIbcOptimization>
+    <UsingToolIbcOptimization Condition="$([MSBuild]::IsOSPlatform('FreeBSD'))">false</UsingToolIbcOptimization>
     <!-- Opt-out repo features -->
     <UsingToolXliff>false</UsingToolXliff>
     <!-- Paths used during restore -->
diff --git a/pkg/Microsoft.NETCore.Platforms/runtimeGroups.props b/pkg/Microsoft.NETCore.Platforms/runtimeGroups.props
index eeb8130b54..6c95b67819 100644
--- a/pkg/Microsoft.NETCore.Platforms/runtimeGroups.props
+++ b/pkg/Microsoft.NETCore.Platforms/runtimeGroups.props
@@ -99,7 +99,7 @@
     <RuntimeGroup Include="freebsd">
       <Parent>unix</Parent>
       <Architectures>x64</Architectures>
-      <Versions>11;11.0;11.1;11.2;11.3</Versions>
+      <Versions>11;12;13</Versions>
     </RuntimeGroup>
 
     <!-- rhel 6 is independent -->
diff --git a/src/Native/Unix/Common/pal_config.h.in b/src/Native/Unix/Common/pal_config.h.in
index e9d397fbb4..abd7b41e59 100644
--- a/src/Native/Unix/Common/pal_config.h.in
+++ b/src/Native/Unix/Common/pal_config.h.in
@@ -42,6 +42,7 @@
 #cmakedefine01 HAVE_STATFS
 #cmakedefine01 HAVE_SYS_SOCKIO_H
 #cmakedefine01 HAVE_SYS_POLL_H
+#cmakedefine01 HAVE_SYS_INOTIFY_H
 #cmakedefine01 HAVE_EPOLL
 #cmakedefine01 HAVE_ACCEPT4
 #cmakedefine01 HAVE_KQUEUE
diff --git a/src/Native/Unix/System.Native/CMakeLists.txt b/src/Native/Unix/System.Native/CMakeLists.txt
index 4251bc5012..376ac24689 100644
--- a/src/Native/Unix/System.Native/CMakeLists.txt
+++ b/src/Native/Unix/System.Native/CMakeLists.txt
@@ -54,6 +54,10 @@ endif ()
 
 if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
     target_link_libraries(System.Native pthread)
+if (HAVE_INOTIFY)
+    find_library(INOTIFY_LIBRARY inotify HINTS /usr/local/lib)
+    target_link_libraries(System.Native ${INOTIFY_LIBRARY})
+endif ()
 endif ()
 
 install_library_and_symbols (System.Native)
diff --git a/src/Native/Unix/System.Security.Cryptography.Native/opensslshim.c b/src/Native/Unix/System.Security.Cryptography.Native/opensslshim.c
index b085114a6b..4cbec07b0b 100644
--- a/src/Native/Unix/System.Security.Cryptography.Native/opensslshim.c
+++ b/src/Native/Unix/System.Security.Cryptography.Native/opensslshim.c
@@ -97,6 +97,21 @@ static bool OpenLibrary()
         DlOpen(MAKELIB("10"));
     }
 
+    if (libssl == NULL)
+    {
+        DlOpen(MAKELIB("11"));
+    }
+
+    if (libssl == NULL)
+    {
+        DlOpen(MAKELIB("111"));
+    }
+
+    if (libssl == NULL)
+    {
+        DlOpen(MAKELIB("8"));
+    }
+
     return libssl != NULL;
 }
 
diff --git a/src/Native/Unix/configure.cmake b/src/Native/Unix/configure.cmake
index 061c40e6a6..ad553177dd 100644
--- a/src/Native/Unix/configure.cmake
+++ b/src/Native/Unix/configure.cmake
@@ -18,6 +18,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
 elseif (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
     set(PAL_UNIX_NAME \"FREEBSD\")
     include_directories(SYSTEM /usr/local/include)
+    set(CMAKE_REQUIRED_INCLUDES /usr/local/include)
 elseif (CMAKE_SYSTEM_NAME STREQUAL NetBSD)
     set(PAL_UNIX_NAME \"NETBSD\")
 elseif (CMAKE_SYSTEM_NAME STREQUAL Emscripten)
@@ -492,6 +493,10 @@ check_c_source_compiles(
     IPV6MR_INTERFACE_UNSIGNED
 )
 
+check_include_files(
+     "sys/inotify.h"
+     HAVE_SYS_INOTIFY_H)
+
 check_c_source_compiles(
     "
     #include <sys/inotify.h>
@@ -672,6 +677,11 @@ check_c_source_compiles(
 )
 set (CMAKE_REQUIRED_FLAGS ${PREVIOUS_CMAKE_REQUIRED_FLAGS})
 
+set (PREVIOUS_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+if (HAVE_SYS_INOTIFY_H AND CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
+    set (CMAKE_REQUIRED_LIBRARIES "-linotify -L/usr/local/lib")
+endif ()
+
 check_function_exists(
     inotify_init
     HAVE_INOTIFY_INIT)
@@ -683,12 +693,15 @@ check_function_exists(
 check_function_exists(
     inotify_rm_watch
     HAVE_INOTIFY_RM_WATCH)
+set (CMAKE_REQUIRED_LIBRARIES ${PREVIOUS_CMAKE_REQUIRED_LIBRARIES})
 
 set (HAVE_INOTIFY 0)
 if (HAVE_INOTIFY_INIT AND HAVE_INOTIFY_ADD_WATCH AND HAVE_INOTIFY_RM_WATCH)
     set (HAVE_INOTIFY 1)
 elseif (CMAKE_SYSTEM_NAME STREQUAL Linux)
     message(FATAL_ERROR "Cannot find inotify functions on a Linux platform.")
+elseif (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
+    message(FATAL_ERROR "Cannot find inotify functions on a FreeBSD platform.")
 endif()
 
 check_c_source_compiles(
diff --git a/src/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj b/src/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
index 8baa7191fc..3a1a9b2add 100644
--- a/src/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
+++ b/src/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
@@ -84,7 +84,7 @@
       <Link>Common\Interop\Unix\Interop.PathConf.cs</Link>
     </Compile>
   </ItemGroup>
-  <ItemGroup Condition=" '$(TargetsLinux)' == 'true'">
+  <ItemGroup Condition=" '$(TargetsLinux)' == 'true' or '$(TargetsFreeBSD)' == 'true'">
     <Compile Include="System\IO\FileSystemWatcher.Linux.cs" />
     <Compile Include="$(CommonPath)\Interop\Linux\System.Native\Interop.INotify.cs">
       <Link>Common\Interop\Linux\Interop.inotify.cs</Link>
@@ -135,7 +135,7 @@
       <Link>Common\System\Text\ValueUtf8Converter.cs</Link>
     </Compile>
   </ItemGroup>
-  <ItemGroup Condition="'$(TargetsFreeBSD)' == 'true' OR '$(TargetsUnknownUnix)' == 'true'">
+  <ItemGroup Condition="'$(TargetsUnknownUnix)' == 'true'">
     <Compile Include="System\IO\FileSystemWatcher.UnknownUnix.cs" />
   </ItemGroup>
   <ItemGroup>
@@ -162,4 +162,4 @@
   <ItemGroup Condition="'$(TargetsUnix)' == 'true'">
     <Reference Include="System.Collections" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
$ ./build.sh --configuration Release --arch x64 --os FreeBSD /p:UpdateRuntimeFiles=true /p:PortableBuild=true /p:OfficialBuildId=20200220.1 /p:ContinuousIntegrationBuild=true
$ cp artifacts/packages/Release/NonShipping/runtime.freebsd-x64.Microsoft.Private.CoreFx.NETCoreApp.4.7.0-servicing.20120.1.nupkg $HOME/nupkg/

Core-Setup

$ cd ../core-setup
$ git checkout 4a9f85e9f89d7f686fef2ae2109d876b1e2eed2a
$ mkdir .dotnet
$ tar xf $HOME/dotnet-sdk-3.1.100-freebsd-x64.tar.gz -C .dotnet/

Required Changes

diff --git a/Directory.Build.props b/Directory.Build.props
index a53af2f0..fa71a14f 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -224,8 +224,6 @@
 
   <PropertyGroup>
     <DisableCrossgen>false</DisableCrossgen>
-    <!-- Disable cross-gen on FreeBSD for now. This can be revisited when we have full support. -->
-    <DisableCrossgen Condition="'$(OSGroup)'=='FreeBSD'">true</DisableCrossgen>
     <OutputVersionBadge>$(AssetOutputPath)sharedfx_$(OutputRid)_$(ConfigurationGroup)_version_badge.svg</OutputVersionBadge>
   </PropertyGroup>
 
@@ -270,6 +268,7 @@
     <TargetsCentos>false</TargetsCentos>
     <TargetsOracle>false</TargetsOracle>
     <TargetsSles>false</TargetsSles>
+    <TargetsFreeBSD>false</TargetsFreeBSD>
   </PropertyGroup>
   <Choose>
     <When Condition="$(OutputRid.StartsWith('win'))">
@@ -346,6 +345,12 @@
         <TargetsUnix>true</TargetsUnix>
       </PropertyGroup>
     </When>
+    <When Condition="$(OutputRid.StartsWith('freebsd'))">
+      <PropertyGroup>
+        <TargetsFreeBSD>true</TargetsFreeBSD>
+        <TargetsUnix>true</TargetsUnix>
+      </PropertyGroup>
+    </When>
     <Otherwise>
       <PropertyGroup>
         <TargetsLinux>true</TargetsLinux>
@@ -398,4 +403,4 @@
     <DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
   </PropertyGroup>
 
-</Project>
\ No newline at end of file
+</Project>
diff --git a/NuGet.config b/NuGet.config
index b06b31e2..40fb8a1f 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -23,6 +23,7 @@
     <add key="dotnet3.1" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1/nuget/v3/index.json" />
     <add key="dotnet3.1-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1-transport/nuget/v3/index.json" />
     <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
+    <add key="local" value="/home/build/nupkg" />
   </packageSources>
   <disabledPackageSources>
     <clear />
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index c22e11fa..50942d22 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -11,8 +11,8 @@
   <PropertyGroup>
     <CrossGenSymbolExtension>.map</CrossGenSymbolExtension>
     <CrossGenSymbolExtension Condition="'$(OSGroup)' == 'Windows_NT'">.ni.pdb</CrossGenSymbolExtension>
-    <!-- OSX doesn't have crossgen symbols, yet -->
-    <CrossGenSymbolExtension Condition="'$(OSGroup)' == 'OSX'"></CrossGenSymbolExtension>
+    <!-- OSX and FreeBSD don't have crossgen symbols, yet -->
+    <CrossGenSymbolExtension Condition="'$(OSGroup)' == 'OSX' or '$(OSGroup)' == 'FreeBSD'"></CrossGenSymbolExtension>
   </PropertyGroup>
 
-</Project>
\ No newline at end of file
+</Project>
diff --git a/src/pkg/projects/netcoreappRIDs.props b/src/pkg/projects/netcoreappRIDs.props
index 7483d182..9171949b 100644
--- a/src/pkg/projects/netcoreappRIDs.props
+++ b/src/pkg/projects/netcoreappRIDs.props
@@ -10,8 +10,7 @@
     <OfficialBuildRID Include="linux-musl-x64" />
     <OfficialBuildRID Include="rhel.6-x64" />
     <OfficialBuildRID Include="osx-x64" />
-    <!-- Not currently built by CoreFX. -->
-    <!-- <OfficialBuildRID Include="freebsd-x64" /> -->
+    <OfficialBuildRID Include="freebsd-x64" />
     <OfficialBuildRID Include="win-x86">
       <Platform>x86</Platform>
     </OfficialBuildRID>
$ ./build.sh --configuration Release /p:OSGroup=FreeBSD /p:PortableBuild=true /p:OfficialBuildId=20200228.1 /p:ContinuousIntegrationBuild=true /nr:false
$ cp artifacts/packages/Release/NonShipping/runtime.freebsd-x64.Microsoft.NETCore.App.3.1.3-servicing.20128.1.nupkg $HOME/nupkg/
$ cp artifacts/packages/Release/Shipping/*freebsd*3.1.3.nupkg $HOME/nupkg/

ASP.NET Core

$ cd ../aspnetcore
$ git checkout e81033e094d4663ffd227bb4aed30b76b0631e6d
$ git submodule update --init --recursive
$ mkdir .dotnet
$ tar xf $HOME/dotnet-sdk-3.1.100-freebsd-x64.tar.gz -C .dotnet/
$ tar xf $HOME/dotnet-runtime-3.1.3-freebsd-x64.tar.gz -C .dotnet/
$ mkdir -p artifacts/obj/Microsoft.AspNetCore.App.Runtime
$ cp $HOME/dotnet-runtime-3.1.3-freebsd-x64.tar.gz artifacts/obj/Microsoft.AspNetCore.App.Runtime/

Required Changes

diff --git a/Directory.Build.props b/Directory.Build.props
index 47f3188693..1cf1dc2b80 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -110,6 +110,7 @@
     <TargetOsName Condition=" '$(TargetOsName)' == '' AND $([MSBuild]::IsOSPlatform('Windows'))">win</TargetOsName>
     <TargetOsName Condition=" '$(TargetOsName)' == '' AND $([MSBuild]::IsOSPlatform('OSX'))">osx</TargetOsName>
     <TargetOsName Condition=" '$(TargetOsName)' == '' AND $([MSBuild]::IsOSPlatform('Linux'))">linux</TargetOsName>
+    <TargetOsName Condition=" '$(TargetOsName)' == '' AND $([MSBuild]::IsOSPlatform('FreeBSD'))">freebsd</TargetOsName>
     <TargetArchitecture Condition="'$(TargetArchitecture)' == ''">x64</TargetArchitecture>
     <TargetRuntimeIdentifier>$(TargetOsName)-$(TargetArchitecture)</TargetRuntimeIdentifier>
 
@@ -123,7 +124,8 @@
       linux-musl-arm64;
       linux-x64;
       linux-arm;
-      linux-arm64
+      linux-arm64;
+      freebsd-x64
     </SupportedRuntimeIdentifiers>
 
     <!-- Make error messages clickable in VS Code's console -->
diff --git a/NuGet.config b/NuGet.config
index d71bb19d79..d0337b84ba 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -16,5 +16,6 @@
     <add key="dotnet3.1" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1/nuget/v3/index.json" />
     <add key="dotnet3.1-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1-transport/nuget/v3/index.json" />
     <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
+    <add key="local" value="/home/build/nupkg" />
   </packageSources>
 </configuration>
diff --git a/build.sh b/build.sh
index b97417c4fa..a30410506b 100755
--- a/build.sh
+++ b/build.sh
@@ -34,6 +34,8 @@ dotnet_runtime_source_feed_key=''
 
 if [ "$(uname)" = "Darwin" ]; then
     target_os_name='osx'
+elif [ "$(uname)" = "FreeBSD" ]; then
+    target_os_name='freebsd'
 else
     target_os_name='linux'
 fi
diff --git a/eng/Dependencies.props b/eng/Dependencies.props
index 8e7bb0ecd5..318efb5c4d 100644
--- a/eng/Dependencies.props
+++ b/eng/Dependencies.props
@@ -113,6 +113,7 @@ and are generated based on the last package release.
     <LatestPackageReference Include="microsoft.netcore.app.runtime.linux-arm64" Version="$(MicrosoftNETCoreAppRuntimeVersion)" />
     <LatestPackageReference Include="microsoft.netcore.app.runtime.linux-musl-x64" Version="$(MicrosoftNETCoreAppRuntimeVersion)" />
     <LatestPackageReference Include="microsoft.netcore.app.runtime.linux-musl-arm64" Version="$(MicrosoftNETCoreAppRuntimeVersion)" />
+    <LatestPackageReference Include="microsoft.netcore.app.runtime.freebsd-x64" Version="$(MicrosoftNETCoreAppRuntimeVersion)" />
   </ItemGroup>
 
   <ItemGroup Label=".NET team dependencies (Non-source-build)" Condition="'$(DotNetBuildFromSource)' != 'true'">
diff --git a/eng/Versions.props b/eng/Versions.props
index d28960c837..769a135d50 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -67,7 +67,7 @@
     <MicrosoftNetCompilersToolsetPackageVersion>3.4.1-beta4-20127-10</MicrosoftNetCompilersToolsetPackageVersion>
     <!-- Packages from dotnet/core-setup -->
     <MicrosoftExtensionsDependencyModelPackageVersion>3.1.3</MicrosoftExtensionsDependencyModelPackageVersion>
-    <MicrosoftNETCoreAppInternalPackageVersion>3.1.3-servicing.20128.1</MicrosoftNETCoreAppInternalPackageVersion>
+    <MicrosoftNETCoreAppInternalPackageVersion>3.1.3</MicrosoftNETCoreAppInternalPackageVersion>
     <MicrosoftNETCoreAppRefPackageVersion>3.1.0</MicrosoftNETCoreAppRefPackageVersion>
     <MicrosoftNETCoreAppRuntimewinx64PackageVersion>3.1.3</MicrosoftNETCoreAppRuntimewinx64PackageVersion>
     <NETStandardLibraryRefPackageVersion>2.1.0</NETStandardLibraryRefPackageVersion>
diff --git a/global.json b/global.json
index b31b810620..e1e9eebf33 100644
--- a/global.json
+++ b/global.json
@@ -1,9 +1,9 @@
 {
   "sdk": {
-    "version": "3.1.102"
+    "version": "3.1.100"
   },
   "tools": {
-    "dotnet": "3.1.102",
+    "dotnet": "3.1.100",
     "runtimes": {
       "dotnet/x64": [
         "$(MicrosoftNETCoreAppInternalPackageVersion)"
diff --git a/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj b/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj
index 6cd9a075a4..f056670f8e 100644
--- a/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj
+++ b/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj
@@ -52,7 +52,7 @@ This package is an internal implementation of the .NET Core SDK and is not meant
 
     <!-- Produce crossgen profiling symbols (.ni.pdb or .map files). -->
     <GenerateCrossgenProfilingSymbols>true</GenerateCrossgenProfilingSymbols>
-    <GenerateCrossgenProfilingSymbols Condition=" '$(CrossgenOutput)' == 'false' OR '$(TargetOsName)' == 'osx'">false</GenerateCrossgenProfilingSymbols>
+    <GenerateCrossgenProfilingSymbols Condition=" '$(CrossgenOutput)' == 'false' OR '$(TargetOsName)' == 'osx' OR '$(TargetOsName)' == 'freebsd'">false</GenerateCrossgenProfilingSymbols>
 
     <!-- Always generated, even though output type == Library -->
     <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

I found ASP.NET Core a bit harder to build so I split these steps out, it made some issue easier to see. So long as you end up with the necessary items in artifacts/packages and artifacts/installers you can probably ignore any warnings or errors. Otherwise try running the build command again, that may be enough.

$ ./build.sh -c Release --arch x64 --os-name freebsd --ci /p:OfficialBuildId=20200313.14 --restore
$ ./build.sh -c Release --arch x64 --os-name freebsd --ci /p:OfficialBuildId=20200313.14 --build
$ ./build.sh -c Release --arch x64 --os-name freebsd --ci /p:OfficialBuildId=20200313.14 --pack
$ cp artifacts/packages/Release/Shipping/Microsoft.AspNetCore.App.Runtime.freebsd-x64.3.1.3.nupkg $HOME/nupkg/
$ cp artifacts/installers/Release/aspnetcore-runtime-internal-3.1.3-freebsd-x64.tar.gz $HOME/

Installer

This repo bundles the SDK.

$ cd ../installer
$ git checkout 6f74c4a1dd4fd0cc49eec7a28984476ed14d09d9
$ mkdir .dotnet
$ tar xf $HOME/dotnet-sdk-3.1.100-freebsd-x64.tar.gz -C .dotnet/
$ mkdir -p artifacts/obj/redist/Release/downloads
$ cp $HOME/dotnet-runtime-3.1.3-freebsd-x64.tar.gz artifacts/obj/redist/Release/downloads/
$ cp $HOME/aspnetcore-runtime-internal-3.1.3-freebsd-x64.tar.gz artifacts/obj/redist/Release/downloads/

Required Changes

diff --git a/NuGet.config b/NuGet.config
index 520c1647c..81d2d27d3 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -23,6 +23,7 @@
     <add key="dotnet3-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3-transport/nuget/v3/index.json" />
     <add key="dotnet3.1" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1/nuget/v3/index.json" />
     <add key="dotnet3.1-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1-transport/nuget/v3/index.json" />
+    <add key="local" value="/home/build/nupkg" />
   </packageSources>
   <disabledPackageSources>
     <clear />
diff --git a/src/redist/targets/GenerateBundledVersions.targets b/src/redist/targets/GenerateBundledVersions.targets
index 7058ceefa..752e92e7e 100644
--- a/src/redist/targets/GenerateBundledVersions.targets
+++ b/src/redist/targets/GenerateBundledVersions.targets
@@ -31,6 +31,7 @@
 
     <ItemGroup>
       <NetCore30RuntimePackRids Include="
+          freebsd-x64;
           linux-arm;
           linux-arm64;
           linux-musl-arm64;
@@ -58,6 +59,7 @@
         linux-x64;
         linux-arm;
         linux-arm64;
+        freebsd-x64;
         " />
 
       <AspNetCoreRuntimePackRids Include="@(AspNetCore30RuntimePackRids)" />
diff --git a/src/redist/targets/SetBuildDefaults.targets b/src/redist/targets/SetBuildDefaults.targets
index 52d64447a..374dd957f 100644
--- a/src/redist/targets/SetBuildDefaults.targets
+++ b/src/redist/targets/SetBuildDefaults.targets
@@ -20,9 +20,6 @@
         AND '$(Rid)' != 'ubuntu.18.04-x64'">true</IncludeSharedFrameworksForBackwardsCompatibilityTests>-->
       <HighEntropyVA>true</HighEntropyVA>
 
-      <!-- There is no asp.net runtime available for freebsd at the moment. Once there is one, we can remove the line below -->
-      <IncludeAspNetCoreRuntime Condition=" '$(IncludeAspNetCoreRuntime)' == '' AND $(Rid.StartsWith('freebsd'))">false</IncludeAspNetCoreRuntime>
-
       <!-- Only use asset target fallback that we set (not implicit one to net461). -->
       <!--<DisableImplicitAssetTargetFallback>true</DisableImplicitAssetTargetFallback>-->
 
$ ./build.sh --configuration Release /p:PortableBuild=true /p:OfficialBuildId=20200317.2 /p:ContinuousIntegrationBuild=true /p:DisableSourceLink=true /nr:false
$ cp artifacts/packages/Release/Shipping/dotnet-sdk-3.1.103-freebsd-x64.tar.gz $HOME/

Using the SDK

To make use of the SDK on a FreeBSD host, you only need the built SDK and packages we saved in nupkg

The canonical location for the SDK is /usr/share/dotnet

The packages are normally hosted by Microsoft on their servers, but in lieu of that solution, you can reference a local cache, e.g. /var/cache/nuget

To perform an install on a host you would copy dotnet-sdk-3.1.103-freebsd-x64.tar.gz and nupkg files to /tmp then

$ sudo pkg install libunwind lttng-ust icu libinotify krb5 openssl
$ sudo mkdir /usr/share/dotnet /var/cache/nuget
$ sudo tar xf /tmp/dotnet-sdk-3.1.103-freebsd-x64.tar.gz -C /usr/share/dotnet/
$ sudo cp /tmp/nupkg/* /var/cache/nuget/

When restoring packages, NuGet will initially configure itself to use the well-known location nuget.org We still require that location to access offical and user-contributed packages, but we need to make sure our FreeBSD packages can also be found. One way is to edit your local NuGet.config and add a line that references the location where you saved the FreeBSD packages.

$ cat $HOME/.nuget/NuGet/NuGet.Config 
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="local" value="/var/cache/nuget" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

Add /usr/share/dotnet to your PATH and that should be everything you need to start building .NET apps on FreeBSD.

.NET Core 3.1 will only every have community support (not a bad thing) but it's not the end of the road. .NET 5.0 is the current focus of development now and I really hope FreeBSD will eventually become a supported platform - that of course relies on the community. We need FreeBSD people to use and contribute to the dotnet repos, this is my effort to get more people involved. The build steps for .NET 5 are actually a lot easier and there is an effort underway to get the automated builds system generating FreeBSD artefacts. In the meantime, the manual steps outlined here should help interested people get off the ground with 3.1

I can't wait to see what people do with it!