question

TorbenJonas-5557 avatar image
0 Votes"
TorbenJonas-5557 asked TorbenJonas-5557 commented

Deploy single project from solution using msbuild and publishing profile

I have a solution with several ASP.NET 4.8 web projects, some of them are "master" projects that get deployed, the remaining projects are modules used by the "master" projects.

Let's assume the solution looks like this:

  • Solution.sln
    • Project1
      • Modules
        • Module1.csproj

        • Module2.csproj

      • Master1.csproj

    • Project2
      • Modules
        • Module1.csproj

        • Module2.csproj

      • Master2.csproj

Each of the master projects has its own pubxml profile for publishing.
The master projects were published using Visual Studio's "Rightclick -> Publish" functionality which uses those profiles.

The master projects have the following setting set so that subdirectories get deployed too:
197017-image.png

I'm tasked to automate this process using cli tools to be able to publish the projects in Azure Pipelines but for now I would like to get it working locally first.
To accomplish this I first tried the following command:

msbuild.exe Solution.sln /t:"Project1\Master1" /p:DeployOnBuild=true /p:PublishProfile=master1publish /p:VisualStudioVersion=17.0

When I execute this command, I get several error complaining that the "master1publish" profile could not be found for all the module projects of Master1.

 C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\Web\Microsoft.Web.Publishing.targets(4438,5):
 error :
 The value for PublishProfile is set to 'master1publish', expected to find the file at 'D:\Solution\Project1\Modules\Module1\Properties\PublishProfiles\master1publish.pubxml' but it could not be found. [D:\Solution\Project1\Master1.csproj]

I searched for this and found out that properties passed to msbuild.exe are global properties and are applied to every project that gets built, so I guess that's why I get the errors.
I also tried to pass the absolute path to the publish profile but it's the same story, msbuild tries to publish each individual sub project.

Next I found a possible solution on Sayed Ibrahim Hashimi - MSBuild, Web Deploy (MSDeploy), ASP.NET - How to publish one web project from a solution (sedodream.com)
A colleague of mine tried this but it didn't really work for some reason, the provided solution isn't really feasible either as we have a lot of modules to change for this.
Visual Studio is able to deploy those projects without applying the provided solution so I guess it should work without it.

A lot of tutorials on how to deploy web projects pass the csproj file to msbuild directly like msbuild.exe Project.csproj ... instead of using the sln file.
Unfortunately we cannot do this as the projects need a solution in order to be buildable in our case.

I don't really know what to do next, it seems that every single tutorial on the internet cannot be applied to the solution I have to work with.
Visual Studio is able to publish those projects using only the pubxml files so my expectation is that there must be a way to replicate this behaviour using msbuild and/or msdeploy.

I really hope that anyone here can suggest me anything to get further with this task.


vs-generalvs-msbuild
image.png (7.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered TorbenJonas-5557 commented

the simplest solution is use two steps:

1) msbuild to build the solution for release
2) msbuild to deploy the project file

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for your answer @Bruce-SqlWork !
Could you elaborate on your answer, specifically on the second part?
I would've guessed that the commands I used so far already do these two steps but how would I just deploy a project file?

0 Votes 0 ·