Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions dotnet/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,23 @@
<None Include="$(ReadMePath)" Pack="true" PackagePath="\" />
</ItemGroup>

<PropertyGroup>
<!-- Optional flag, defaults to false -->
<InstallMissingTools Condition="'$(InstallMissingTools)' == ''">false</InstallMissingTools>
</PropertyGroup>

<Target Name="CheckPrereqs" BeforeTargets="Build">
<Exec Condition=" '$(OS)' == 'Windows_NT' and '$(InstallMissingTools)' == 'true' "
Command="powershell -ExecutionPolicy Bypass -File $(MSBuildThisFileDirectory)eng\check-prereqs.ps1 -InstallMissing" />

<Exec Condition=" '$(OS)' == 'Windows_NT' and '$(InstallMissingTools)' != 'true' "
Command="powershell -ExecutionPolicy Bypass -File $(MSBuildThisFileDirectory)eng\check-prereqs.ps1" />

<Exec Condition=" '$(OS)' != 'Windows_NT' and '$(InstallMissingTools)' == 'true' "
Command="bash $(MSBuildThisFileDirectory)eng/check-prereqs.sh --install-missing" />

<Exec Condition=" '$(OS)' != 'Windows_NT' and '$(InstallMissingTools)' != 'true' "
Command="bash $(MSBuildThisFileDirectory)eng/check-prereqs.sh" />
</Target>

</Project>
69 changes: 69 additions & 0 deletions dotnet/eng/check-prereqs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
param (
[switch]$InstallMissing
)

$ErrorActionPreference = "Stop"
$Missing = @()

function Check-Command {
param ([string]$Name)
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
Write-Host ("Missing: {0,-10} - not found in PATH" -f $Name)
$script:Missing += $Name
}
else {
Write-Host ("Found: {0,-10}" -f $Name)
}
}

function Install-Tool {
param ([string]$Tool)
Write-Host "Installing $Tool..."

switch ($Tool) {
"python" {
if (Get-Command winget -ErrorAction SilentlyContinue) {
winget install -e --id Python.Python.3
}
elseif (Get-Command choco -ErrorAction SilentlyContinue) {
choco install python3 -y
}
else {
Write-Host "No supported package manager (winget or choco) found."
exit 1
}
}
"uv" {
Invoke-WebRequest -Uri "https://astral.sh/uv/install.ps1" -UseBasicParsing | Invoke-Expression
}
default {
Write-Host "No install logic defined for: $Tool"
exit 1
}
}
}

Write-Host "Checking for required tools..."
Check-Command python
Check-Command uv

if ($Missing.Count -gt 0) {
Write-Host "`nMissing tools detected: $Missing"

if ($InstallMissing) {
foreach ($tool in $Missing) {
Install-Tool $tool
}
Write-Host "`nAll missing tools installed."
}
else {
Write-Host "`nSome required tools are missing. Re-run with '--install-missing' to install them."
Write-Host ""
Write-Host "For manual setup instructions, see:"
Write-Host "https://github.com/microsoft/autogen/blob/main/python/README.md#setup"
exit 1
}
}
else {
Write-Host "`nAll required tools are installed."
}
69 changes: 69 additions & 0 deletions dotnet/eng/check-prereqs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash
set -euo pipefail

MISSING=()
INSTALL=false

if [[ "${1:-}" == "--install-missing" ]]; then
INSTALL=true
fi

check_command() {
local name=$1
if ! command -v "$name" &>/dev/null; then
printf "Missing: %-10s - not found in PATH\n" "$name"
MISSING+=("$name")
else
printf "Found: %-10s\n" "$name"
fi
}

install_tool() {
local tool=$1
echo "Installing $tool..."
case "$tool" in
python3)
if command -v brew &>/dev/null; then
brew install python
elif command -v apt &>/dev/null; then
sudo apt update && sudo apt install -y python3
elif command -v dnf &>/dev/null; then
sudo dnf install -y python3
else
echo "Unsupported package manager. Please install $tool manually."
return 1
fi
;;
uv)
curl -Ls https://astral.sh/uv/install.sh | sh
;;
*)
echo "No install method defined for: $tool"
return 1
;;
esac
}

echo "Checking for required tools..."
check_command python3
check_command uv

if [ ${#MISSING[@]} -ne 0 ]; then
echo ""
echo "Missing tools detected: ${MISSING[*]}"

if [ "$INSTALL" = true ]; then
for tool in "${MISSING[@]}"; do
install_tool "$tool"
done
echo "All missing tools have been installed."
else
echo "Some required tools are missing. Use '--install-missing' to install them automatically."
echo ""
echo "For manual setup instructions, see: "
echo "https://github.com/microsoft/autogen/blob/main/python/README.md#setup"
exit 1
fi
else
echo "All required tools are installed."
fi