diff --git a/dotnet6.0.spec b/dotnet6.0.spec
index 0bf8d9c..2d775db 100644
--- a/dotnet6.0.spec
+++ b/dotnet6.0.spec
@@ -86,6 +86,8 @@ Source11: dotnet.sh.in
Patch100: runtime-arm64-lld-fix.patch
# Mono still has a dependency on (now unbuildable) ILStrip which was removed from CoreCLR: https://github.com/dotnet/runtime/pull/60315
Patch101: runtime-mono-remove-ilstrip.patch
+# Add Fedora 40 RIDs
+Patch102: runtime-fedora-40-rid.patch
# Disable apphost, needed for s390x
Patch500: fsharp-no-apphost.patch
@@ -389,9 +391,17 @@ ln -s %{_libdir}/dotnet/source-built-artifacts/Private.SourceBuilt.Artifacts.*.t
# Fix bad hardcoded path in build
sed -i 's|/usr/share/dotnet|%{_libdir}/dotnet|' src/runtime/src/native/corehost/hostmisc/pal.unix.cpp
+%if 0%{?fedora} == 40
+# Fix incorrectly using fedora.39 RIDs on fedora.40
+sed -i -E 's|(true)|\1%{runtime_id}false|' \
+ src/aspnetcore/src/Tools/dotnet-dev-certs/src/dotnet-dev-certs.csproj \
+ src/aspnetcore/src/Tools/dotnet-user-secrets/src/dotnet-user-secrets.csproj \
+%endif
+
pushd src/runtime
%patch100 -p1
%patch101 -p1
+%patch102 -p1
popd
pushd src/fsharp
@@ -440,6 +450,8 @@ cat /etc/os-release
%if %{without bootstrap}
# We need to create a copy because we will mutate this
cp -a %{_libdir}/dotnet previously-built-dotnet
+sed -i -E 's|fedora.33|fedora.40|' previously-built-dotnet/sdk/6.0.120/RuntimeIdentifierGraph.json
+
find previously-built-dotnet
%endif
diff --git a/runtime-fedora-40-rid.patch b/runtime-fedora-40-rid.patch
new file mode 100644
index 0000000..c80fc44
--- /dev/null
+++ b/runtime-fedora-40-rid.patch
@@ -0,0 +1,98 @@
+From 8bafc61a5e0b172e030b3c354ee7a9dc1d113a3a Mon Sep 17 00:00:00 2001
+From: Omair Majid
+Date: Wed, 9 Aug 2023 16:43:30 -0400
+Subject: [PATCH] Add Fedora 40 RID
+
+---
+ .../src/runtime.compatibility.json | 32 +++++++++++++++++++
+ .../src/runtime.json | 17 ++++++++++
+ .../src/runtimeGroups.props | 2 +-
+ 3 files changed, 50 insertions(+), 1 deletion(-)
+
+diff --git a/src/libraries/Microsoft.NETCore.Platforms/src/runtime.compatibility.json b/src/libraries/Microsoft.NETCore.Platforms/src/runtime.compatibility.json
+index bf9dcefffef..79e07f75eed 100644
+--- a/src/libraries/Microsoft.NETCore.Platforms/src/runtime.compatibility.json
++++ b/src/libraries/Microsoft.NETCore.Platforms/src/runtime.compatibility.json
+@@ -4432,6 +4432,38 @@
+ "any",
+ "base"
+ ],
++ "fedora.40": [
++ "fedora.40",
++ "fedora",
++ "linux",
++ "unix",
++ "any",
++ "base"
++ ],
++ "fedora.40-arm64": [
++ "fedora.40-arm64",
++ "fedora.40",
++ "fedora-arm64",
++ "fedora",
++ "linux-arm64",
++ "linux",
++ "unix-arm64",
++ "unix",
++ "any",
++ "base"
++ ],
++ "fedora.40-x64": [
++ "fedora.40-x64",
++ "fedora.40",
++ "fedora-x64",
++ "fedora",
++ "linux-x64",
++ "linux",
++ "unix-x64",
++ "unix",
++ "any",
++ "base"
++ ],
+ "freebsd": [
+ "freebsd",
+ "unix",
+diff --git a/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json b/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json
+index 4bc419bbfde..8fbe76a76b4 100644
+--- a/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json
++++ b/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json
+@@ -1498,6 +1498,23 @@
+ "fedora-x64"
+ ]
+ },
++ "fedora.40": {
++ "#import": [
++ "fedora"
++ ]
++ },
++ "fedora.40-arm64": {
++ "#import": [
++ "fedora.40",
++ "fedora-arm64"
++ ]
++ },
++ "fedora.40-x64": {
++ "#import": [
++ "fedora.40",
++ "fedora-x64"
++ ]
++ },
+ "freebsd": {
+ "#import": [
+ "unix"
+diff --git a/src/libraries/Microsoft.NETCore.Platforms/src/runtimeGroups.props b/src/libraries/Microsoft.NETCore.Platforms/src/runtimeGroups.props
+index 5fe956f0be5..e596bf65aae 100644
+--- a/src/libraries/Microsoft.NETCore.Platforms/src/runtimeGroups.props
++++ b/src/libraries/Microsoft.NETCore.Platforms/src/runtimeGroups.props
+@@ -71,7 +71,7 @@
+
+ linux
+ x64;arm64
+- 23;24;25;26;27;28;29;30;31;32;33;34;35;36;37;38;39
++ 23;24;25;26;27;28;29;30;31;32;33;34;35;36;37;38;39;40
+ false
+
+
+--
+2.41.0
+