Skip to content

Instantly share code, notes, and snippets.

@luoxufeiyan
Created May 30, 2024 08:42
Show Gist options
  • Save luoxufeiyan/b3c245ed461350235072f0ced85b17af to your computer and use it in GitHub Desktop.
Save luoxufeiyan/b3c245ed461350235072f0ced85b17af to your computer and use it in GitHub Desktop.
递归地检查目录及其子目录中是否存在NuGet文件,并在找到NuGet文件时将其推送到指定的源中
import os
import subprocess
def push_nuget_packages(directory, source):
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".nupkg"):
nuget_file_path = os.path.join(root, file)
command = f"dotnet nuget push {nuget_file_path} -s {source}"
try:
subprocess.run(command, check=True, shell=True)
print(f"Successfully pushed {nuget_file_path} to {source}")
except subprocess.CalledProcessError as e:
print(f"Failed to push {nuget_file_path}: {e}")
if __name__ == "__main__":
directory_to_check = "/path/to/your/directory" # 替换为你要检查的目录路径
nuget_source = "mytest" # 替换为你的NuGet源
push_nuget_packages(directory_to_check, nuget_source)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment