Command-line Package Service Fabric Application

纵然是瞬间 提交于 2021-02-06 10:55:36

问题


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?


回答1:


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




回答2:


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.




回答3:


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.

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"




回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/37079742/command-line-package-service-fabric-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!