101 lines
4.4 KiB
Bash
Executable File
101 lines
4.4 KiB
Bash
Executable File
#!/usr/bin/env nix-shell
|
|
#! nix-shell -i bash --pure
|
|
#! nix-shell -p bash which xmlstarlet
|
|
|
|
if [[ ! $# -eq 1 ]]; then
|
|
echo "Usage: $0 <dotnet-path>"
|
|
exit 1
|
|
fi
|
|
|
|
dotnet_path=$1
|
|
|
|
function stderr() {
|
|
echo "$@" 1>&2;
|
|
}
|
|
|
|
function create_settings_file() {
|
|
cat << EOF
|
|
<?xml version="1.0"?>
|
|
<wpf:ResourceDictionary
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
xmlns:s="clr-namespace:System;assembly=mscorlib"
|
|
xmlns:ss="urn:schemas-jetbrains-com:settings-storage-xaml"
|
|
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
xml:space="preserve"
|
|
>
|
|
<s:String x:Key="/Default/Environment/Hierarchy/Build/BuildTool/DotNetCliExePath/@EntryValue">${1}</s:String>
|
|
<s:String x:Key="/Default/Environment/Hierarchy/Build/BuildTool/CustomBuildToolPath/@EntryValue">${2}</s:String>
|
|
</wpf:ResourceDictionary>
|
|
EOF
|
|
}
|
|
|
|
# HACK: Configure Rider to use the correct .NET paths from an ambient .NET
|
|
function use_rider_dotnet() {
|
|
local solution_file=$(find . -maxdepth 1 -type f -name '*.slnx' | cut -d'.' -f2 | cut -d'/' -f2)
|
|
local settings_file=$(find . -maxdepth 1 -type f -name '*.sln.DotSettings.user')
|
|
# Get paths
|
|
local cli_path=$(realpath "$dotnet_path")
|
|
local dir=$(dirname $cli_path)
|
|
local msbuild_path=$(find "$dir" -maxdepth 3 -type f -name MSBuild.dll)
|
|
|
|
# stderr "dotnet path is $dir"
|
|
# stderr "Found msbuild: $msbuild_path"
|
|
|
|
if [ -f "$settings_file" ] ; then
|
|
# stderr "Updating rider settings file: $settings_file"
|
|
# stderr "Setting DotNetCliExePath to $cli_path"
|
|
|
|
# NOTE: check if dotnet binary in share folder settings exists
|
|
xml sel -t -v "wpf:ResourceDictionary/s:String[@x:Key='/Default/Environment/Hierarchy/Build/BuildTool/DotNetCliExePath/@EntryValue']" "$settings_file"
|
|
if [[ $? -eq 0 ]]; then
|
|
xml ed --inplace \
|
|
-N wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" \
|
|
-N x="http://schemas.microsoft.com/winfx/2006/xaml" \
|
|
-N s="clr-namespace:System;assembly=mscorlib" \
|
|
-N ss="urn:schemas-jetbrains-com:settings-storage-xaml" \
|
|
--update "//s:String[@x:Key='/Default/Environment/Hierarchy/Build/BuildTool/DotNetCliExePath/@EntryValue']" \
|
|
--value "$cli_path" \
|
|
"$settings_file"
|
|
else
|
|
xml ed --inplace \
|
|
-N wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" \
|
|
-N x="http://schemas.microsoft.com/winfx/2006/xaml" \
|
|
-N s="clr-namespace:System;assembly=mscorlib" \
|
|
-N ss="urn:schemas-jetbrains-com:settings-storage-xaml" \
|
|
-s /wpf:ResourceDictionary -t elem -n s:String -v "$cli_path" \
|
|
--var new_node '$prev' \
|
|
-i '$new_node' -t attr -n "x:Key" -v "/Default/Environment/Hierarchy/Build/BuildTool/DotNetCliExePath/@EntryValue" \
|
|
"$settings_file"
|
|
fi
|
|
|
|
xml sel -t -v "wpf:ResourceDictionary/s:String[@x:Key='/Default/Environment/Hierarchy/Build/BuildTool/CustomBuildToolPath/@EntryValue']" "$settings_file"
|
|
if [[ $? -eq 0 ]]; then
|
|
xmlstarlet ed --inplace \
|
|
-N wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" \
|
|
-N x="http://schemas.microsoft.com/winfx/2006/xaml" \
|
|
-N s="clr-namespace:System;assembly=mscorlib" \
|
|
-N ss="urn:schemas-jetbrains-com:settings-storage-xaml" \
|
|
--update "//s:String[@x:Key='/Default/Environment/Hierarchy/Build/BuildTool/CustomBuildToolPath/@EntryValue']" \
|
|
--value "$msbuild_path" \
|
|
"$settings_file"
|
|
else
|
|
xml ed --inplace \
|
|
-N wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" \
|
|
-N x="http://schemas.microsoft.com/winfx/2006/xaml" \
|
|
-N s="clr-namespace:System;assembly=mscorlib" \
|
|
-N ss="urn:schemas-jetbrains-com:settings-storage-xaml" \
|
|
-s /wpf:ResourceDictionary -t elem -n s:String -v "$cli_path" \
|
|
--var new_node '$prev' \
|
|
-i '$new_node' -t attr -n "x:Key" -v "/Default/Environment/Hierarchy/Build/BuildTool/CustomBuildToolPath/@EntryValue" \
|
|
"$settings_file"
|
|
fi
|
|
else
|
|
create_settings_file $cli_path $msbuild_path > "$solution_file.sln.DotSettings.user"
|
|
fi
|
|
}
|
|
|
|
function main() {
|
|
use_rider_dotnet
|
|
}
|
|
|
|
main |