Replies: 4 comments 1 reply
-
What I often do in generic build scripts in cases like this is to search the
Here is an example using this approach in Cake.Recipe: https://github.com/cake-contrib/Cake.Recipe/blob/b72068881d7785a9429167592389e8524c4382e8/Cake.Recipe/Content/packages.cake#L252 |
Beta Was this translation helpful? Give feedback.
-
If you have a That said you can fetch all generated nupkg files with a globber and do something like var packages = GetFiles(outputNuGet.Path.FullPath + "/*.nupkg") -
GetFiles(outputNuGet.Path.FullPath + "/*.symbols.nupkg");
foreach(var package in packages)
{
NuGetPush(package, new NuGetPushSettings {
Source = source,
ApiKey = apiKey
});
} |
Beta Was this translation helpful? Give feedback.
-
Just a quick note that although it's common to retrieve a list of artifacts generated during the build and publish them in bulk (to make the code smaller/less repetitive), it's also a good practice to (before the publishing) validate that: 1. All the packages you expect to be published are actually present in your artifacts folderOtherwise your build will appear to have succeeded incorrectly - as you didn't push all the packages you expected 2. No other packages are present in your artifacts folderIn case of errors in your build, you don't want to push the wrong packages to the feed Here's a simple example that detects missing files as well as files that shouldn't be there, and fails the build in either case: var version = "...";
var expectedFiles = new []
{
MakeAbsolute(FilePath.FromString($"./packages/YourPackage.{version}.nupkg")).FullPath,
MakeAbsolute(FilePath.FromString($"./packages/YourPackage.{version}.snupkg")).FullPath,
};
var actualFiles = GetFiles("./packages/**/*.*").Select(f => f.FullPath).ToList();
var missingFiles = expectedFiles.Except(actualFiles).ToList();
foreach (var missingFile in missingFiles)
{
Error("Error: Artifact {0} is missing", missingFile);
}
var unexpectedFiles = actualFiles.Except(expectedFiles).ToList();
foreach (var unexpectedFile in unexpectedFiles)
{
Error("Error: Artifact {0} was not expected", unexpectedFile);
}
if (missingFiles.Count > 0 || unexpectedFiles.Count > 0)
{
throw new CakeException();
} |
Beta Was this translation helpful? Give feedback.
-
Thanks for all your proposals @devlead @augustoproiete @pascalberger It would have been far simpler if To reduce code (do not query version from assembly) and avoid error prone logic (id/version expectations), I made my mind for this sequence (in each single-project build task):
I guess it will be easy to read/understand/maintain for others. |
Beta Was this translation helpful? Give feedback.
-
Hello
I am interested to implement a generic build/push logic in a monorepo context.
My current build file generate .nupkg from csproj file with
NuGetPack(project, new NuGetPackSettings { OutputDirectory = "packages/" });
And I would like then to publish file with
NuGetPush(package, new NuGetPushSettings { Source: "local-source", });
Is there a way to infer/compute/retrieve generated package file path from
NuGetPack
command?Beta Was this translation helpful? Give feedback.
All reactions