Lee Z
Lee Z

Reputation: 964

Azure DevOps build pipeline for Service Fabric Guest .Net Core 3.1 API exe fails on creating package

I have a .NET Core 3.1 API that I am attempting to deploy as a Guest Executable in Service Fabric using an Azure DevOps build pipeline. The platform for all projects/configurations is x64.

I have locally tested the API and also locally tested the API running as a guest executable within service fabric. I am able to build/rebuild the API and I am able to package the service fabric application.

In my build pipeline, I have the following steps shown in the picture below.

enter image description here

The Create Service Fabric Package is defined in the picture below

enter image description here

When the build pipeline runs, it always fails with the error:

##[error]AppraisalStatusUpdatesContainer\AppraisalStatusUpdatesContainer.sfproj(0,0): Error MSB4057: The target "Package" does not exist in the project.

I cannot find any documentation on what to do to solve this issue and have spent a couple of days trying. Does anyone know how to get this to work?

Edit 1

The sfproj is provided below

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.props" Condition="Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.props')" />
  <PropertyGroup Label="Globals">
    <ProjectGuid>ffefa7ed-cf72-4780-9910-816deed2ed4f</ProjectGuid>
    <ProjectVersion>2.5</ProjectVersion>
    <MinToolsVersion>1.5</MinToolsVersion>
    <SupportedMSBuildNuGetPackageVersion>1.6.10</SupportedMSBuildNuGetPackageVersion>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
  </PropertyGroup>
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <ItemGroup>
    <None Include="ApplicationPackageRoot\ApplicationManifest.xml" />
    <None Include="ApplicationParameters\Prod.xml" />
    <None Include="ApplicationParameters\QA.xml" />
    <None Include="ApplicationParameters\UAT.xml" />
    <None Include="ApplicationParameters\Local.1Node.xml" />
    <None Include="ApplicationParameters\Local.5Node.xml" />
    <None Include="PublishProfiles\QA.xml" />
    <None Include="PublishProfiles\UAT.xml" />
    <None Include="PublishProfiles\Prod.xml" />
    <None Include="PublishProfiles\Local.1Node.xml" />
    <None Include="PublishProfiles\Local.5Node.xml" />
    <None Include="Scripts\Deploy-FabricApplication.ps1" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="..\AppraisalStatusUpdates\bin\Release\netcoreapp3.1\publish\**\*.*">
      <Link>ApplicationPackageRoot\AppraisalStatusUpdatesContainerPkg\Code\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <Content Include="ApplicationPackageRoot\AppraisalStatusUpdatesContainerPkg\Config\Settings.xml" />
    <Content Include="ApplicationPackageRoot\AppraisalStatusUpdatesContainerPkg\ServiceManifest.xml" />
    <Content Include="packages.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
  <PropertyGroup>
    <ApplicationProjectTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Service Fabric Tools\Microsoft.VisualStudio.Azure.Fabric.ApplicationProject.targets</ApplicationProjectTargetsPath>
  </PropertyGroup>
  <Import Project="$(ApplicationProjectTargetsPath)" Condition="Exists('$(ApplicationProjectTargetsPath)')" />
  <Import Project="..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets')" />
  <Target Name="ValidateMSBuildFiles" BeforeTargets="PrepareForBuild">
    <Error Condition="!Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.props')" Text="Unable to find the '..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.props' file. Please restore the 'Microsoft.VisualStudio.Azure.Fabric.MSBuild' Nuget package." />
    <Error Condition="!Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets')" Text="Unable to find the '..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets' file. Please restore the 'Microsoft.VisualStudio.Azure.Fabric.MSBuild' Nuget package." />
  </Target>
</Project>

Edit 2 @LeoLiu-MSFT, I have attempted the approach you mentioned. I am not getting the original error, but am now attempting to resolve the subsequent issues that resulted. Also, I am doing dotnet publish and dotnet test tasks before this step. It seems like the publish step is unnecessary except that it is needed for running the tests.

My msbuild step is now as follows

Service Fabric MSBuild Step

This results in the exception below:

##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(777,5): Error : The OutputPath property is not set for project 'AppraisalStatusUpdatesContainer.sfproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Release' Platform='x64'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project.

Upvotes: 0

Views: 1165

Answers (2)

Leo Liu
Leo Liu

Reputation: 76770

Azure DevOps build pipeline for Service Fabric Guest .Net Core 3.1 API exe fails on creating package

According to the error:

MSB4057: The target "Package" does not exist in the project.

When you are using MSBuild for a solution of projects (.sln) with target Package, but not all projects have the Package task defined. That may be one of the reasons why you get this error.

To resolve this issue, we could add following custom target in the .sfproj file:

  <Target Name="ForcePackageTarget" AfterTargets="Build" Condition="'$(ForcePackageTarget)' =='true'">
    <CallTarget Targets="Package"/>
  </Target>

Then add /p:ForcePackageTarget=true as an argument to the msbuild build task.

Please check this thread and this post for some more details.

Upvotes: 0

Preben Huybrechts
Preben Huybrechts

Reputation: 6111

I have a custom Powershell script in my service fabric repositories for this. It does a separate nuget restore for .sfproj.

The script restore-sf.ps1:

Push-Location $PSScriptRoot
$ProjectFolder = "..\src\YourProjectFolder"

$PackageFolder = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\Packages"))

Push-Location $ProjectFolder

nuget restore YourServiceFabricProject.sfproj -PackagesDirectory $PackageFolder -MSBuildVersion 15

Pop-Location
Pop-Location

My folder structure:

├───Root
    ├───packages
    ├───src
        ├───YourProjectFolder
            ├───YourServiceFabricProject.sfproj  
    ├───scripts
        ├───restore-sf.ps1

Depending on your folder structure, you'll need to change the paths in the script.

In the pipeline one of the first steps is to call the script, to restore the Microsoft.VisualStudio.Azure.Fabric.MSBuild package.

The script assumes nuget is available in the path.

Upvotes: 0

Related Questions