How to create Azure Cloud Service package from MsBuild in azure pipeline

人盡茶涼 提交于 2019-12-13 04:44:28

问题


I have some cloud service projects , which i am trying to get it into CI/CD. When i right click on the project from Visual Studio and click Package it does what i want. I can see the ServiceConfiguration.cscfg and ServiceDefinition.csdef in the bin\Release folder after the package command is completed.

How can i achieve the same from an MSBuild command line ? I have tried

msbuild.exe 
/p:DeployTarget=Package 
/p:DeployOnBuild=true 
/p:AutomatedBuild=True 
/p:configuration=release 
/p:outdir="D:\Pub" 
/p:targetprofile="Cloud" 
/target:Publish  
/p:SolutionDir=$/src/mysln/ WorkerRole.ccproj

What i get is the command completes and i can see around 241 dll and the required files in the folder. Am i missing something in the command argument ? Please advice

Edit : Also refered the official docs , could'nt find anything

Edit 2 : Looks like i can get the packages generated. Now the problem is doing this in VSTS. The build is failing with " projectfile="*Undefined*Obfuscator\Maps\

Basically the solution path is becoming as undefined

Edit 3 : Here's the error message when i try to build only the CloudServiceProj

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(5165,5): Error MSB3073: The command "if "Release" == "Debug" goto :exit
"*Undefined*Obfuscator\Tool\CO" projectfile="*Undefined*Obfuscator\Maps

The undefined is working fine locally , since it has the $(SolutionDir) variable in VS. Not sure how do i handle it here

Update

Here's the msbuild that am using

Update 4

I tried building the solution directly as suggested, but it has some .NET CORE as well as .NET Framework projects and i am getting this error

C:\Program Files\dotnet\sdk\2.2.105\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\Microsoft.NET.Sdk.Publish.targets(163,11): Error MSB4006: There is a circular dependency in the target dependency graph involving target "Publish"..


回答1:


What i get is the command completes and i can see around 241 dll and the required files in the folder. Am i missing something in the command argument ?

For this question, you can try to change the argument /p:outdir="D:\Pub" to /p:PublishDir="D:\Pub". That because the argument outdir is used to stored the output files not the publish files, it contains the build output of the projects (including the reference project). That the reason why there are around 241 dll and the required files in the folder.

As I test, if I change the argument to PublishDir, it works fine:

For the second question, I am not familiar with Azure Cloud Service, as I know about MSBuild/Visual Studio, we should build the "main" project instead of the reference project, so you can try to build the AzureCloudService.ccproj or build the solution file .sln.

Besides, when we build the project/solution, we do not need specify the solution folder, just specify the project file or solution directly:

msbuild.exe "TheRelativePathForYourSolutionInRepos.sln" /t:Publish /p:DeployOnBuild=true /p:AutomatedBuild=True /p:configuration=release /p:TargetProfile=Cloud /p:PublishDir="D:\Pub"

If above not resolve your questions, please share your build error log in your question.

Update:

For the second part, I have a post build event which does some obfuscation .

If you have use any Macros, like $(SolutionDir) in your build event, but build the project file, you will got that error. Because the project reference information exists in the solution information, we can't access it when we only build one project.

Try to replace all $(SolutionDir) with $(ProjectDir)..\

Update2:

Since you can build the .sln file on your local without any issue, you could also build the .sln file with Azure pipeline. As test, I could build the .sln file in the Azure pipeline:

Besides, if you have replace $(SolutionDir) with $(ProjectDir)..\, how do you still get the error Undefined? Try to double check you build event, or you can share it in the question.

Hope this helps.



来源:https://stackoverflow.com/questions/56130619/how-to-create-azure-cloud-service-package-from-msbuild-in-azure-pipeline

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