Skip to content

Commit 7646fad

Browse files
SyncFileContentsSyncFileContents
authored andcommitted
Sync scripts\update-winget-manifests.ps1
1 parent b704b85 commit 7646fad

1 file changed

Lines changed: 56 additions & 100 deletions

File tree

scripts/update-winget-manifests.ps1

Lines changed: 56 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ function Test-IsLibraryOnlyProject {
123123
$isExecutable = ($csprojContent -match "<OutputType>\s*Exe\s*</OutputType>" -or
124124
$csprojContent -match "<OutputType>\s*WinExe\s*</OutputType>" -or
125125
$csprojContent -match 'Sdk="[^"]*\.App["/]' -or
126-
$csprojContent -match 'Sdk="[^"]*Sdk\.App["/]')
126+
$csprojContent -match 'Sdk="[^"]*Sdk\.App["/]' -or
127+
$csprojContent -match '<Sdk\s+Name="[^"]*\.App"\s*/>' -or
128+
$csprojContent -match '<Sdk\s+Name="[^"]*Sdk\.App"\s*/>')
127129

128130
# Check if it's a library (explicit markers or implicit)
129131
$isLibrary = ($csprojContent -match "<OutputType>\s*Library\s*</OutputType>" -or
@@ -133,6 +135,9 @@ function Test-IsLibraryOnlyProject {
133135
$csprojContent -match 'Sdk="[^"]*\.Lib["/]' -or
134136
$csprojContent -match 'Sdk="[^"]*Sdk\.Lib["/]' -or
135137
$csprojContent -match 'Sdk="[^"]*Library[^"]*"' -or
138+
$csprojContent -match '<Sdk\s+Name="[^"]*\.Lib"\s*/>' -or
139+
$csprojContent -match '<Sdk\s+Name="[^"]*Sdk\.Lib"\s*/>' -or
140+
$csprojContent -match '<Sdk\s+Name="[^"]*Library[^"]*"\s*/>' -or
136141
$csprojContent -match "<TargetFrameworks>" -or # Multiple target frameworks often = library
137142
(-not $isExecutable)) # No explicit exe = library by default
138143

@@ -184,121 +189,62 @@ function Exit-GracefullyForLibrary {
184189
exit 0
185190
}
186191

187-
function Get-MSBuildProperties {
192+
function Get-MSBuildProperty {
188193
param (
189-
[string]$ProjectPath
194+
[string]$ProjectPath,
195+
[string]$PropertyName
190196
)
191197

192198
try {
193-
# Check if MSBuild is available
194-
$msbuild = $null
195-
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
196-
197-
if (Test-Path $vsWhere) {
198-
# Use Visual Studio installation path
199-
$vsPath = & $vsWhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
200-
if ($vsPath) {
201-
$msbuildPath = Join-Path $vsPath "MSBuild\Current\Bin\MSBuild.exe"
202-
if (-not (Test-Path $msbuildPath)) {
203-
# Try older VS versions
204-
$msbuildPath = Join-Path $vsPath "MSBuild\15.0\Bin\MSBuild.exe"
205-
}
206-
207-
if (Test-Path $msbuildPath) {
208-
$msbuild = $msbuildPath
209-
}
210-
}
199+
$dotnetPath = Get-Command dotnet -ErrorAction SilentlyContinue
200+
if (-not $dotnetPath) {
201+
return $null
211202
}
212203

213-
# If VS installation not found, try .NET SDK's MSBuild
214-
if (-not $msbuild) {
215-
$dotnetPath = Get-Command dotnet -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
216-
if ($dotnetPath) {
217-
$msbuild = "dotnet msbuild"
204+
# Use dotnet msbuild with /getProperty to get the evaluated property value
205+
$result = & dotnet msbuild "$ProjectPath" /nologo /t:Build /p:DesignTimeBuild=true /getProperty:$PropertyName 2>$null
206+
if ($LASTEXITCODE -eq 0 -and $result) {
207+
$value = $result.Trim()
208+
if ($value -and $value -ne "") {
209+
return $value
218210
}
219211
}
212+
}
213+
catch {
214+
# Silently fail, caller will handle null
215+
}
220216

221-
if (-not $msbuild) {
222-
Write-Host "MSBuild not found. Falling back to XML parsing." -ForegroundColor Yellow
223-
return $null
224-
}
217+
return $null
218+
}
225219

226-
# Create temporary file to store properties
227-
$tempFile = [System.IO.Path]::GetTempFileName()
228-
229-
# Prepare MSBuild command
230-
$propertiesToEvaluate = "AssemblyName;RootNamespace;PackageId;Product;Authors;Version;Description;RepositoryUrl;Copyright;PackageTags"
231-
$msbuildArgs = @(
232-
"`"$ProjectPath`"",
233-
"/nologo",
234-
"/t:_GetProjectProperties",
235-
"/p:PropertiesToEvaluate=$propertiesToEvaluate",
236-
"/p:OutputFile=`"$tempFile`""
237-
)
238-
239-
# Create target file with task to write properties to file
240-
$targetFile = [System.IO.Path]::GetTempFileName() + ".targets"
241-
242-
@"
243-
<Project>
244-
<Target Name="_GetProjectProperties">
245-
<ItemGroup>
246-
<_PropertiesToWrite Include="`$(PropertiesToEvaluate)" />
247-
</ItemGroup>
248-
249-
<PropertyGroup>
250-
<_PropOutput></_PropOutput>
251-
</PropertyGroup>
252-
253-
<CreateItem Include="`$(PropertiesToEvaluate)">
254-
<Output TaskParameter="Include" ItemName="PropertiesToWrite" />
255-
</CreateItem>
256-
257-
<!-- Evaluate and write each property -->
258-
<CreateProperty Value="`$(_PropOutput)%0A$([System.Environment]::NewLine)%(PropertiesToWrite.Identity)=$([System.Environment]::NewLine)$([Microsoft.Build.Evaluation.ProjectProperty]::GetPropertyValue('%(PropertiesToWrite.Identity)'))">
259-
<Output TaskParameter="Value" PropertyName="_PropOutput" />
260-
</CreateProperty>
261-
262-
<WriteLinesToFile File="`$(OutputFile)" Lines="`$(_PropOutput)" Overwrite="true" />
263-
264-
<Message Text="Project properties written to `$(OutputFile)" Importance="high" />
265-
</Target>
266-
</Project>
267-
"@ | Out-File -FilePath $targetFile -Encoding UTF8
268-
269-
# Run MSBuild
270-
if ($msbuild -eq "dotnet msbuild") {
271-
$result = & dotnet msbuild @msbuildArgs "/p:CustomBeforeMicrosoftCommonTargets=$targetFile"
272-
} else {
273-
$result = & $msbuild @msbuildArgs "/p:CustomBeforeMicrosoftCommonTargets=$targetFile"
274-
}
220+
function Get-MSBuildProperties {
221+
param (
222+
[string]$ProjectPath
223+
)
275224

276-
# Check if output file was created
277-
if (-not (Test-Path $tempFile)) {
278-
Write-Host "MSBuild did not generate properties file. Falling back to XML parsing." -ForegroundColor Yellow
225+
try {
226+
$dotnetPath = Get-Command dotnet -ErrorAction SilentlyContinue
227+
if (-not $dotnetPath) {
228+
Write-Host "dotnet CLI not found. Falling back to XML parsing." -ForegroundColor Yellow
279229
return $null
280230
}
281231

282-
# Read properties
283-
$propertiesText = Get-Content $tempFile -Raw
284232
$properties = @{}
233+
$propertyNames = @("AssemblyName", "RootNamespace", "PackageId", "Product", "Authors", "Version", "Description", "RepositoryUrl", "Copyright", "PackageTags")
285234

286-
foreach ($line in ($propertiesText -split "`n")) {
287-
$line = $line.Trim()
288-
if ($line -match "^([^=]+)=(.*)$") {
289-
$propName = $Matches[1].Trim()
290-
$propValue = $Matches[2].Trim()
291-
if ($propName -and $propValue) {
292-
$properties[$propName] = $propValue
293-
}
235+
foreach ($propName in $propertyNames) {
236+
$value = Get-MSBuildProperty -ProjectPath $ProjectPath -PropertyName $propName
237+
if ($value) {
238+
$properties[$propName] = $value
294239
}
295240
}
296241

297-
# Clean up temp files
298-
Remove-Item $tempFile -Force -ErrorAction SilentlyContinue
299-
Remove-Item $targetFile -Force -ErrorAction SilentlyContinue
242+
if ($properties.Count -gt 0) {
243+
return $properties
244+
}
300245

301-
return $properties
246+
Write-Host "MSBuild property evaluation returned no results. Falling back to XML parsing." -ForegroundColor Yellow
247+
return $null
302248
}
303249
catch {
304250
Write-Host "Error evaluating MSBuild properties: $_" -ForegroundColor Yellow
@@ -431,6 +377,7 @@ function Find-ProjectInfo {
431377
shortDescription = ""
432378
description = ""
433379
publisher = ""
380+
rootNamespace = ""
434381
}
435382

436383
# Try to get version from VERSION.md
@@ -538,6 +485,10 @@ function Find-ProjectInfo {
538485
}
539486
}
540487
}
488+
489+
if ($msBuildProps.RootNamespace) {
490+
$projectInfo.rootNamespace = $msBuildProps.RootNamespace
491+
}
541492
} else {
542493
# Fallback to parsing the csproj XML
543494
Write-Host "Falling back to parsing csproj XML" -ForegroundColor Yellow
@@ -567,6 +518,10 @@ function Find-ProjectInfo {
567518
if ($csprojContent -match "<Authors>(.*?)</Authors>") {
568519
$projectInfo.publisher = $Matches[1].Split(',')[0].Trim()
569520
}
521+
522+
if ($csprojContent -match "<RootNamespace>(.*?)</RootNamespace>") {
523+
$projectInfo.rootNamespace = $Matches[1]
524+
}
570525
}
571526
}
572527

@@ -789,7 +744,7 @@ if ($projectInfo.version -and -not $Version) {
789744

790745
# Build configuration object with detected and provided values
791746
$config = @{
792-
packageId = if ($PackageId) { $PackageId } elseif ($config.packageId) { $config.packageId } else { "$owner.$repo" }
747+
packageId = if ($PackageId) { $PackageId } elseif ($config.packageId) { $config.packageId } elseif ($projectInfo.rootNamespace) { $projectInfo.rootNamespace } else { "$owner.$repo" }
793748
githubRepo = $GitHubRepo
794749
artifactNamePattern = if ($ArtifactNamePattern) { $ArtifactNamePattern } elseif ($config.artifactNamePattern) { $config.artifactNamePattern } else { "$repo-{version}-{arch}.zip" }
795750
executableName = if ($ExecutableName) { $ExecutableName } elseif ($config.executableName) { $config.executableName } elseif ($projectInfo.executableName) { $projectInfo.executableName } else { "$repo.exe" }
@@ -1008,16 +963,17 @@ InstallModes:
1008963
- interactive
1009964
- silent
1010965
UpgradeBehavior: install
1011-
$commandsYaml
1012-
$fileExtensionsYaml
966+
$($commandsYaml.TrimEnd())
967+
$($fileExtensionsYaml.TrimEnd())
1013968
ReleaseDate: $releaseDate
1014969
Dependencies:
1015970
PackageDependencies:
971+
1016972
"@
1017973

1018974
# Add .NET dependency based on project type
1019975
if ($projectInfo.type -eq "csharp") {
1020-
$installerContent += " - PackageIdentifier: Microsoft.DotNet.DesktopRuntime.9`n"
976+
$installerContent += " - PackageIdentifier: Microsoft.DotNet.DesktopRuntime.10`n"
1021977
}
1022978

1023979
$installerContent += "Installers:`n"

0 commit comments

Comments
 (0)