Skip to content

Added a PowerShell script to validate NuGet packages #423

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dakanev-msft
Copy link
Member

Added a PowerShell script which can be used as a step in the PR validation pipeline to prevent creating new projects without the required attributes.

@dakanev-msft dakanev-msft requested a review from a team as a code owner October 14, 2021 14:39
@@ -0,0 +1,150 @@
<#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this script? I think we are running dotnet pack as part of PR build (or we should) so better way might be changing its severity (simular to what ADO does) to fail on missing data or other errors. Also look into https://devblogs.microsoft.com/dotnet/package-validation/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The publishing to NuGet.org fails if some attributes are missing, e.g. projecturl

I took a look at the package validation link, but I could not find a way to validate if a particular attribute is present in the nuspec file.

I agree that having this validation in the pack step is the preferred way. Do you know how we could use the pack validation to achieve this?

Copy link
Contributor

@AndreyTretyak AndreyTretyak Oct 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it's some kind of parameter that ADO pass to dotnet pack task, but github does not, so we can just compare logs.
Also if we need some custom validation I think having MSBuild target in Directories.Build.targets would be much simpler and it would run automatically.
For example:

<Target Name="ValidateNugetPackage" BeforeTargets="pack" Condition="'$(IsPackable)' == 'true'">
    <Error Condition="'$(Tags)' == ''" Text="Tags should not be empty" />
    ...
<Target>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I tried to add these conditions to Directories.Build.targets but it didn't work because these attributes were always evaluated as empty - for some reason it did not take into account attributes from csproj files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants