7

MsBuild.exe MyProject.csproj /p:Configuration=Release /p:DebugType=None /p:Optimize=True /p:DeployOnBuild=true /p:PublishProfile=MyPublishProfile /p:VisualStudioVersion=16.0"

We used to run above command to build and published webapp using MsBuild.exe. This is working fine whenever we are using MsBuild packaged along with VS 2019. Path: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin

However, as soon as we are using MsBuild that came along with VS2022, it is compiling project but not publishing.

Can anyone provide some light why publish is not working when running above command with MsBuild VS 2022?

Note: This project is targeting .Net framework 4.7.

0

3 Answers 3

4

You need to use the "Publish" target. The following does work for me using MSBuild from VS2022 for my .NET 7.0 project:

MSbuild.exe "C:\SomePath\SomeProject.csproj" -p:Configuration="YourProjectConfiguration" -restore -t:Publish -p:PublishProfile="NameOfPublishProfile"
Sign up to request clarification or add additional context in comments.

Comments

2

This link tell you that MSBuild 17.0 shipped with Visual Studio 2022 and .NET 6.0. https://learn.microsoft.com/en-us/visualstudio/msbuild/whats-new-msbuild-17-0?view=vs-2019

You can refer to the following link to solve the problem: First, enter “msbuild -ver” in the command line tool to view the version of msbuild.

enter image description here

Then change the command “/p:VisualStudioVersion=16.0 “ to “/p:VisualStudioVersion=17.2.1 “.

It works in my test.

enter image description here

1 Comment

I tried changing the version but no luck. It's same behavior with version 16.0. For both cases Build is successful but it's not publishing.
1

Question is for .NET Framework. Just in case someone has this issue with .NET (formerly Core). I fixed it like that. As mentioned in comments, this slightly another topic.

I Just gave up on this taking all the parameters stored in publish profile and pass it manually, this seems to work with VS 2022

dotnet publish "C:\SomePath\SomeProject.csproj" -r win-x64 -p:PublishSingleFile=true --self-contained true -p:PublishReadyToRun=true -p:PublishDir=relative\newDirPublish

3 Comments

OP asked for MSBuild, not dotnet CLI. I am looking for the same problem, i.e. MSBuild for the .net framework
Yes you're right. with MSBuild this worked for me, just had the issue with sdk-style-projects (.net core) which need to be published with dotnet-cli (as far as i know). msbuild somproject.csproj /p:DeployOnBuild=true /p:PublishProfile="PROD Publish" /p:Configuration=Release
again as OP mentioned, it is for .NET Framework so this answers doesn't covers the problem statement

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.