10

Our continuous delivery set-up, until recently, was delivering Service Fabric packages using the following command:

msbuild SFApp.sfproj /t:Package

This was necessary because the target Package is unavailable at the solution level. I.e. The command

msbuild SFSolution.sln /t:Package

Fails, as the target does not exist.

As our dependency mesh grows, it gets to a point in which most interfaces projects will not build without a solution file (to work around the "OutputPath does not exist" red herring). There seems to be a way to do that according to this answer. Unfortunately, while targets like Clean work…

msbuild SFSolution.sln /t:SFApplication:Clean
(…snip…)
Build succeeded.
    0 Warning(s)
    0 Error(s)

…the target Package won't!

msbuild SFSolution.sln /t:SFApplication:Package
(…snip…)
Build FAILED.
"SFSolution.sln" (SFApplication:Package target) (1) -> SFSolution.sln.metaproj :
        error MSB4057: The target "SFApplication:Package" does not exist in the
        project. [SFSolution.sln]
    0 Warning(s)
    1 Error(s)

(Solution/project folders/names omitted/paraphrased for clarity. I can provide the actual logs if necessary.)

So the question is: how could I, using the Command Line, build one project using the Package target and the solution file?

Or how can I otherwise package a Service Fabric application from the command line?

Community
  • 1
  • 1
Liz Av
  • 2,864
  • 1
  • 25
  • 35
  • Due to an employment change, this question is no longer relevant to me and I will likely never be able to accept an answer. Even if someone puts in the time to come up with the correct solution, I won't be able to verify its correctness. – Liz Av Apr 06 '18 at 15:20
  • I will however add that the problem was ultimately solved by migrating to VSTS. We never figured out how to use MSBuild for this one purpose. – Liz Av Apr 06 '18 at 15:24

5 Answers5

13

It's bad idea to compile sfproj file(and any other project file) without sln, because it can bring wrong content to its output from referenced projects. Only solution has a knowledge about what project to compile in what configuration.

To make Package similar to "Right Click->Package" in VS: Just add to your sfproj the following target

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

And then running normal build on solution you may trigger the package step by /p:ForcePackageTarget=true :

msbuild yoursolution.sln /t:Build /p:ForcePackageTarget=true /p:Configuration=Release /p:Platform=x64

Actually it performs two-in-one steps, build and package, with respect to Solution Configurations on all referenced projects

jenkas
  • 872
  • 14
  • 16
  • 2
    This is what did it for me. Additionally, a penny just dropped as to why/what the solution file actually does (all about configuration sets and it essentially setting the projects up according to which ever config). Thank you! – Jaans Sep 28 '19 at 14:22
1

MSBuild only supports a small set of target names that can be specified at the solution level. As you've discovered, Package is not one of them. You'll need to execute two separate calls to MSBuild: one which builds the solution and one which calls the Package target on the sfproj. The Package target of an sfproj has a dependency on the Build target so it will ensure that the sfproj and its project dependencies are built.

Matt Thalman
  • 3,540
  • 17
  • 26
  • That does not work. No change if I run one exactly after the other. See http://pastebin.com/uMjdSJ1Q Lines: [1] build CLI [296] package CLI [542] first OutputPath error [629] last error – Liz Av May 06 '16 at 20:11
  • 3
    According to the build output, your solution configuration is configured to use AnyCPU. The .sfproj and its referenced projects are configured to use x64. You'll need to update the solution configuration appropriately. – Matt Thalman May 06 '16 at 20:31
  • Have you tried create a new Service Fabric application project and trying to build it from the command line in the same manner? If that test project works, then we'd at least now it's a configuration issue in your project. It's tough to say what the issue might be from that build output paste. Can you provide build output with diagnostic verbosity turned on? – Matt Thalman May 11 '16 at 16:33
1

I had the same problem and fixed it by changing the Platform in the failing projects to explicitly build for x64.

Click Build > Configuration Manager and make sure that the assemblies are compiled for the x64 platform, that should also set the Output Paths in the corresponding .csproj files.enter image description here

The actual command line action that is being executed is this:

"C:\Program Files (x86)\MSBuild\14.0\bin\amd64\msbuild.exe" "C:\agent\_work\1\s\Project\SFProject.sfproj" /t:Package /p:platform="x64" /p:configuration="release" /p:VisualStudioVersion="14.0"

Stephanvs
  • 723
  • 7
  • 19
1

Use the below script.

C:\Program Files (x86)\Microsoft Visual Studio 14.0> msbuild "Fabric.sfproj" /t:Package /p:Configuration=Release

Service fabric requires Target to be set in x64 platform, So change all you reference projects target to x64 platform.

you can do this by using configuration properties of your solution. If x64 is not listed in 'Configuration Properties' click configuration manager in the same window and under platform column for the required project add new project platform as x64.

Hope this works for you.

Venkatesh
  • 269
  • 1
  • 11
-1

We have had the exact same problem as you had and I have been looking around for a solution all over the web and did some experiments. Those are the steps that worked for us:

  1. Don't manually add a target anywhere as suggested by other answers on StackOverflow. Not necessary. Especially in a CI environment, you want to build the projects separately anyways.
  2. Prepare the projects in the Solution: Change the target platform for all projects to x64
  3. Build the application

msbuild.exe SFAplication.xproj /p:Configuration=Release /target:rebuild

  1. Package the App

msbuild.exe SFAplication.sfproj /p:Configuration=Release /target:Package

Structed
  • 304
  • 8
  • 19