Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-832: Use dotnet CLI in Add-SourceLinkPackage #341

Merged
merged 4 commits into from
Mar 30, 2024
Merged
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
42 changes: 1 addition & 41 deletions .github/actions/publish-nuget/Add-SourceLinkPackage.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
# Register NuGet.org as a package source since GitHub runners don't necessarily have it by default.
$existingSource = Get-PackageSource -Name NuGet.org -ErrorAction SilentlyContinue

if (-not $existingSource)
{
Register-PackageSource -Name NuGet.org -Location https://api.nuget.org/v3/index.json -ProviderName NuGet
}
else
{
Write-Output 'Package source for NuGet.org is already registered.'
}

# Get the latest version of the package.
$latestPackage = Find-Package -Name Microsoft.SourceLink.GitHub -Source NuGet.org | Sort-Object Version -Descending | Select-Object -First 1
$latestVersion = $latestPackage.Version

# Find solution file.
$solutionFile = Get-ChildItem -Path . -Filter *.sln -Recurse | Select-Object -First 1

Expand All @@ -33,29 +17,5 @@ else

foreach ($projectFile in $projectFiles)
{
Write-Output "Processing project: $($projectFile.FullName)"

# Load the project file as XML.
$projectXml = [xml](Get-Content -Path $projectFile.FullName)

# Define the xmlns to access the elements in the csproj.
$namespaceManager = New-Object Xml.XmlNamespaceManager $projectXml.NameTable
$namespaceManager.AddNamespace('ns', $projectXml.DocumentElement.NamespaceURI)

# Create a new ItemGroup.
$itemGroup = $projectXml.CreateElement('ItemGroup', $projectXml.DocumentElement.NamespaceURI)

# Create a new PackageReference.
$packageNode = $projectXml.CreateElement('PackageReference', $projectXml.DocumentElement.NamespaceURI)
$packageNode.SetAttribute('Include', 'Microsoft.SourceLink.GitHub')
$packageNode.SetAttribute('Version', $latestVersion)

# Add the package to the ItemGroup.
$itemGroup.AppendChild($packageNode)

# Add the new ItemGroup to the project.
$projectXml.Project.AppendChild($itemGroup)

# Save the changes back to the .csproj file.
$projectXml.Save($projectFile.FullName)
dotnet add $projectFile.FullName package 'Microsoft.SourceLink.GitHub' --source 'https://api.nuget.org/v3/index.json'
}
Loading