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 Studio2019円\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.

asked May 18, 2022 at 22:02
1
  • I'm facing the same problem now. Any solutions yet? Commented Aug 3, 2022 at 11:19

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"
answered Feb 10, 2023 at 7:44
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

answered May 19, 2022 at 6:41

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
answered Oct 10, 2022 at 8:30

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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.