如何在Nexus Repository存储ASP.NET Core应用构建文件?求替代方案
Hey there! Since you're having trouble storing ASP.NET Core DLLs directly in your Nexus Repository, let's walk through some practical alternatives that fit nicely with your existing setup (since you already have NuGet packages hosted there):
This is the most seamless option because Nexus already supports NuGet repositories, and you're already using this for dependencies. Here's how to do it:
- Using dotnet CLI: If your ASP.NET Core project is a class library, run this command from your project directory to create a NuGet package:
This generates adotnet pack YourProject.csproj -c Release.nupkgfile in thebin/Releasedirectory, which includes your DLLs and metadata (like version numbers) defined in your.csproj. - Manual nuspec file: For more control over package contents (e.g., including extra files), create a
.nuspecfile and run:nuget pack YourProject.nuspec -Version 1.0.0
Once you have the nupkg, push it to your Nexus NuGet repository using dotnet nuget push or the Nexus UI—just like you did with your dependency packages.
Why this works: NuGet packages are purpose-built for .NET assets, so they integrate naturally with build tools, support versioning, and let you manage dependencies alongside your existing packages.
If you don't want to package your DLLs into a NuGet package, Nexus's Raw Repository is perfect for storing arbitrary files (including DLLs). Here's how to set it up and use it:
- In Nexus, create a new Hosted Repository with the format set to
raw. - Upload your DLLs either via the Nexus UI (browse to the repository, click "Upload Component") or using
curl:curl -u your-nexus-username:your-password -X PUT "http://your-nexus-domain/repository/your-raw-repo/path/to/YourApp.dll" --data-binary @./bin/Release/net6.0/YourApp.dll
Why this works: Raw repositories have no restrictions on file types, so you can store single DLLs or entire sets of build artifacts without any packaging overhead.
If you need to store your entire ASP.NET Core build output (DLLs, config files, static assets, etc.) together, bundle them into a zip archive and upload it to a Nexus Raw Repository:
- Use your OS's zip tool or a CLI command to package the contents of your build directory:
# On Linux/macOS zip -r app-build-v1.0.zip ./bin/Release/net6.0/ # On Windows (PowerShell) Compress-Archive -Path ./bin/Release/net6.0/* -DestinationPath app-build-v1.0.zip
Then upload the zip file to your Raw Repository using the same methods as above.
Why this works: This keeps all your application's build artifacts together, making it easy to download and deploy the entire app in one go.
If you're using containerization for deployment, package your ASP.NET Core app into a Docker image and push it to a Nexus Docker Repository:
- Create a
Dockerfilefor your app (example for ASP.NET Core 6):FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base WORKDIR /app EXPOSE 80 FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build WORKDIR /src COPY ["YourProject.csproj", "."] RUN dotnet restore "./YourProject.csproj" COPY . . WORKDIR "/src/." RUN dotnet build "YourProject.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "YourProject.csproj" -c Release -o /app/publish /p:UseAppHost=false FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "YourProject.dll"] - Build the image and tag it with your Nexus Docker repository URL:
docker build -t your-nexus-domain/docker-repo/your-app-image:v1.0 . - Push the image to Nexus:
docker push your-nexus-domain/docker-repo/your-app-image:v1.0
Why this works: Containerization encapsulates your app and its dependencies, making deployment consistent across environments, and Nexus fully supports Docker image hosting.
内容的提问来源于stack exchange,提问作者Isuru Amarathunga

