10
votes

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.

Screenshot from VSTS

4
Can you show the build logs here?Marina Liu

4 Answers

16
votes

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'.

6
votes

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>
1
votes

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. Project-Dependencies

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

0
votes

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.

Link settings dialog box