'dotnet publish only one project from the solution in VSTS
We are trying to build one project from a Visual Studio solution in VSTS with .NET Core task. We are able to "dotnet build" that project. But when we try to "dotnet publish" it tries to publish all projects from the solution. Even if we use "dotnet custom", it tries to publish all projects.
Is there a way to use .NET Core task to publish only one project or projects that were built? Or should we run a custom command line task?
Reason for this is that we have a project that won't build and we don't need/want to publish it. So we would like to build and publish one project and not all projects.
Solution 1:[1]
You can use dotnet publish <Path to .csproj>. This will build and publish only the specified project and projects it depends on.
In order to specify a project in the '.Net Core' task with the command 'publish' you have to uncheck 'Publish Web Projects'.
Solution 2:[2]
Another solution would be to set IsPublishable in csproj.
I usually do it in cases where it's a unit test project or else that doesn't need to be published if you run dotnet publish for solution file.
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable >
<Configurations>prod;stage;dev</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
Solution 3:[3]
This is decided on Project Dependencies for each projects.
In other words, there are some configuration to say that "which project need to build first, in order to let your target project successfully build."
If you are using Visual Studio, right click on solution and click 'Properties'.
In this example, my target run is TestAngular.Web.Host and in order to build that projects, it's required to build TestAngular.Web.Core first.

If you are using different IDE, simply locate to your directory, in my case it would be src\TestAngular.Web.Host and modify TestAngular.Web.Host.csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<ItemGroup>
<ProjectReference Include="..\TestAngular.Web.Core\TestAngular.Web.Core.csproj" />
</ItemGroup>
...
</Project Sdk="Microsoft.NET.Sdk.Web">
Add or remove which projects are not required here following same syntax
Solution 4:[4]
If you un-check the 'Publish Web Projects' you will see a field appear that allows you to enter the project (csproj) you want to target.
Solution 5:[5]
Maybe late to the party but in order to have control over what projects to publish, you could unlink the "Path to project(s)" variable (by clicking on "Link settings"). That makes the field editable and you can specify your desired .csproj.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Andrey Borisko |
| Solution 3 | Jacky |
| Solution 4 | Ben D |
| Solution 5 | Walden2 |


