C# 如何禁止在发布管道中使用nuget包的预发布版本

C# 如何禁止在发布管道中使用nuget包的预发布版本,c#,azure-devops,nuget,azure-pipelines,C#,Azure Devops,Nuget,Azure Pipelines,如果预发布版本中有nugget软件包,是否可能“失败”发布 也许Azure DevOps中已经有此任务,或者可能有一种方法可以使用Powershell执行此任务?您可以使用Powershell读取.csproj文件,并检查是否存在预发布版本,如果是,则出错: [xml]$csproj = Get-Content path/to/csproj/file # e.g. $(Agent.ReleaseDirectory)/myproject/myproject.csproj $versions = $

如果预发布版本中有nugget软件包,是否可能“失败”发布


也许Azure DevOps中已经有此任务,或者可能有一种方法可以使用Powershell执行此任务?

您可以使用Powershell读取
.csproj
文件,并检查是否存在预发布版本,如果是,则出错:

[xml]$csproj = Get-Content path/to/csproj/file # e.g. $(Agent.ReleaseDirectory)/myproject/myproject.csproj
$versions = $csproj.Projects.ItemGroup.PackageReference.Version
$versions.ForEach({

   # Pre-releases are with '-' symbol, e.g. 1.0.0-beta
   if($_ -match "(?<number>\d-)")
   {
       Write-Error "Pre-release exist: $_"
   }

})
[xml]$csproj=获取内容路径/to/csproj/file#例如$(Agent.ReleaseDirectory)/myproject/myproject.csproj
$versions=$csproj.Projects.ItemGroup.PackageReference.Version
$versions.ForEach({
#预发行版带有“-”符号,例如1.0.0-beta
如果($匹配“(?\d-”)
{
写入错误“存在预发行版本:$\u”
}
})
解决方案(如果您想从SLN文件中获取数据包)如下所示:

Get-Content .\SolutionName.sln |
where { $_ -match "Project.+, ""(.+)""," } |
foreach { $matches[1] } |
% { Get-Content $_ -ErrorAction SilentlyContinue |
Find "<PackageReference Include" } |
Sort-Object -Unique |
% { if($_ -match "-test") { Write-Host "You're using a PreRelease Version for the following Package $($_)"} }
获取内容。\SolutionName.sln|
其中{$\匹配“Project.+,”(.+),“}|
foreach{$matches[1]}|
%{获取内容$\uErrorAction SilentlyContinue|

查找“您的意思是-如果在
packags.config
中有一个具有预发布版本的nuget包吗?注意:如果您正在构建一个包,NU5104已经为您完成了这项工作;我假设这是一个顶级可部署的”内容"那么?@shaykibaramczyk我没有package.config文件。这是一个.Net核心解决方案,并且引用了Nugget。据我所知,.csproj的文件保留了nuget包的引用。我只想知道在所有nuget之间,是否至少有一个在预发布中。如果有,那么我希望发布失败。@MarcGravel No、 我不是在构建nuget。我只是想知道,我正在部署的解决方案是否有一些具有预发布版本的包。如果是这种情况,我希望发布“失败”。
get-childitem "$(get-location)" -recurse |
where {$_.extension -eq ".csproj"}|
% { Get-Content $_.FullName -ErrorAction SilentlyContinue |
Find "<PackageReference Include" } |
Sort-Object -Unique |
% { if($_ -match "-test") { Write-Error "You're using a PreRelease Version for the following Package $($_)"} }