sdk: Unable to publish multiple projects at the same time.
When i publish with dotnet cli, the output is:
publish: Published to …/output/project1 Published 1/1 projects successfully
Which indicates i could publish multiple projects at te same time (why else say: 1/1)
so i tried this.
Steps to reproduce
dotnet publish project1 project2 -o ../output
Expected behavior
I expect 2 projects to be published in this output folder (each in there own folder, having the same name as the project folder).
Actual behavior
Unrecognized command or argument project2
Environment data
.NET Command Line Tools (1.0.0-preview2-1-003155)
Product Information:
Version: 1.0.0-preview2-1-003155
Commit SHA-1 hash: d7b0190bd4
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 16
- Comments: 55 (12 by maintainers)
This is a 3 year old issue that should be trivial to fix, so I’m not sure why this is still lingering around? Several suggested solutions have been presented and even the referencing issues to this one outline how this mistake came to be.
-oappend each project name (just like pack is doing) to create a sub folder for each project.It does not make sense to dump everything to a single folder when publishing a solution and I would argue that when it would, this feature would be the minority and you would want a flag to enable it as the amount of issues this can cause has been outlined in other issues.
For now, I have choosen to build tooling around my tooling and removed the
-oparam and have instead wrote a script to recursively find all the publish folders generated under each project and to move them to a root level folder.Closing issue, there is probably an alternative by now.
@joelharkes why was this closed? There is no alternative solution and nothing in this issue suggests there is.
@piotrpMSFT I think multi publish should be considered.
Our architecture is made up of 2 kestrel console apps and 3 other console applications. now i have to execute 5 times
dotnet publish. 5 times going over library projects and all executing in synchronous order (otherwise i don’t know if it will run into locking problems with trying to build the same project). This is a lot of overhead. if this is managed by the CLI, projects could be run asynchronously, speeding up the build performance with a big factor.@neman That is exactly what you want to avoid for 2 main reasons:
I made a script that builds the dependency trees for all projects and then executes builds in parallel (Promises nodejs) according to the builds. I got a major decrease in build/publish time (on a multi core environment).
Too bad though our build server agents only use 1 processor per agent but, but locally for developers its still better this way.
I’ve managed to bring down build+test time by using msbuild scripts like this (even in non-parallel builds): https://gist.github.com/dasMulli/69f5303aa79a8cd4060e44891c90fd2d
Essentially, making a single
build.projfile that calls publish on others via<MSBuild/>tasks (=>dotnet msbuild build.proj.^ would be nice to have something like this for Github Actions!
This is can be easy be done with powershell script. You just have to create for each project build/publish script, and then execute it within loop. This way I build/publish/create nuget/push nuget with one command for more than 30 projects in one solution.
This code could be in some PublishMultipleProjects.ps1 script. You can extend this by adding parms what to include and so on…
found this which seems relevant:
https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish You can publish a solution (not just a project).
this was added in .NET Core 3.0
This would be helpful for us.
something like:
The it could publish them in folders individually or just publish the ones specified in the folders (sometimes there’s libraries in the solution you wouldn’t want published by itself)
It finally works!
I hope this helps someone else out; it did work for my pipeline, building multiple project with one command. After trying multiple configurations, this is what worked for me.
I added modifyOutputPath: true to the
dotnet publishtask and it seems to work now with-o <root directory>argument. I have not tested withdotnet buildor other commands.my YAML task:
We build a single docker image for our Api and Cli projects (we use the Cli project to run k8s jobs, like run migrations before deploying the new Api version). We want to publish those two projects and their dependencies without having the test projects and their dependencies.
Since this issue was reported nearly 5 years ago, someone bothered to change the error instead of resolving the actual issue:
MSBUILD : error MSB1008: Only one project can be specified.Based on the comment from @williamdenton we can have both scenarios described here (publish to separate folders and publish to a single folder) for a solution file. So why not for multiple projects from the command line? Sure, I can create a .sln for any combination of projects I’d want to publish in a single go but surely it shouldn’t be too difficult to just fix this?
@Lanayx no this is exactly what doesn’t work, and what brought me to this issue. Running
dotnet publish -o outputPathon the solution will not create a separate folder for each project, it will dump everything into the single folderoutputPath.@gandarez when you say “The MSBUILD does not have that behaviour”, how have you been using msbuild? the msbuild equivalent of
dotnet publish -o foowould bemsbuild /t:Publish /p:PublishDir=foo. If you have been using/p:DeployOnBuild=truewith a publish profile, that is a different way of publishing specific to asp.net and asp.net core and may behave differently. It should also be noted that if you pass a relative path to the-oparameter, it is always interpreted relative to the individual csproj file, not relative to the path thedotnet publishcommand is invoked from.@KathleenDollard The solution contains two web api core projects and I’m using dot net publish to publish them. But the cli put every single project to the same root output directory. The MSBUILD does not have that behaviour, it groups each project in its respective folder.
@blackdwarf will propose the intention change here.