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.
-
I'm facing the same problem now. Any solutions yet?marsze– marsze2022年08月03日 11:19:47 +00:00Commented Aug 3, 2022 at 11:19
3 Answers 3
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"
Comments
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.
Then change the command "/p:VisualStudioVersion=16.0 " to "/p:VisualStudioVersion=17.2.1 ".
It works in my test.
1 Comment
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
Explore related questions
See similar questions with these tags.