Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSBuild commandline seems to ignore publish properties #1901

Closed
paleocomburo opened this issue Mar 23, 2017 · 96 comments
Closed

MSBuild commandline seems to ignore publish properties #1901

paleocomburo opened this issue Mar 23, 2017 · 96 comments

Comments

@paleocomburo
Copy link

@paleocomburo paleocomburo commented Mar 23, 2017

I'm trying to use msbuild to publish my application to a filesystem location. I've setup a profile from inside VS2017 and from there it works perfectly.
When I run msbuild from the commandline: "msbuild application.sln /p:DeployOnBuild=true /p:PublishProfile=publishprofile" it builds the default "Debug|x86" target and nothing else. Nothing is published and the target in the publish profile is set to "release".
When I specify a non-existing publish profile it still build like above, while I would expect an error telling me I specified a non-existing profile.

@oexenhave
Copy link

@oexenhave oexenhave commented Mar 29, 2017

+1 I'm having the same issue. The following command builds correctly, but doesn't output anything to the deploy target. The exact same command works on a machine with VS2015 installed.

"C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe" /t:Build;Publish TCA.Web\TCA.Web.csproj /p:DeployOnBuild=true /p:PublishProfile=Deploy.pubxml /p:Configuration=Release

I see the following in the build output, but unable to extract why it happens.
_DeploymentUnpublishable:
Skipping unpublishable project.

It works from the Visual Studio 2017 UI. I'm running build 15.0.0+26228.10

@frbar
Copy link

@frbar frbar commented Mar 31, 2017

Same for me.

@faemm
Copy link

@faemm faemm commented Apr 11, 2017

Same for me too,

@ducseb
Copy link

@ducseb ducseb commented Apr 21, 2017

Same for me

1 similar comment
@ewilli
Copy link

@ewilli ewilli commented Apr 24, 2017

Same for me

@frbar
Copy link

@frbar frbar commented Apr 24, 2017

Hi, still no news from Microsoft's guys? MSBuild 14 cannot build C# 7 code.

Is it possible to build with v15 and do the publish (and only the publish) with 14?

@tran-barry
Copy link

@tran-barry tran-barry commented Apr 24, 2017

Same here

@deadlydog
Copy link

@deadlydog deadlydog commented Apr 26, 2017

Same for me

@jamest-iqmetrix
Copy link

@jamest-iqmetrix jamest-iqmetrix commented Apr 26, 2017

Same here.

@vicp-iq
Copy link

@vicp-iq vicp-iq commented Apr 26, 2017

Ditto.

@RyanMarcotte
Copy link

@RyanMarcotte RyanMarcotte commented Apr 26, 2017

Same here

@andrewk-iq
Copy link

@andrewk-iq andrewk-iq commented Apr 26, 2017

Me as well

@shkup
Copy link

@shkup shkup commented Apr 27, 2017

Same here.
I try to run publish only (This method worked in previous versions)
MSBuild <PROJECT_PATH> /t:publish /p:PublishProfile=<PUBLISH_PROFILE_PATH> /p:PublishRootDir=<PATH_VARIABLE_FOR_THE_PROFILE> /p:Configuration=Release

@VincentLangevin
Copy link

@VincentLangevin VincentLangevin commented Apr 27, 2017

I'm also encountering the same problem

@rainersigwald
Copy link
Contributor

@rainersigwald rainersigwald commented Apr 27, 2017

I tried to reproduce this but don't think I did, on a new WebApplication type project created in VS2015 U3 and published on the command line from both VS2015 U3 and VS2017 15.1.

Can someone affected by this please post repro steps that are excruciatingly clear, for someone who has never used "publish" before like me? Ideally with a small repro project I could build in various ways, and explicit descriptions of the behavior you expect and what you see instead.

@mattlwilliams
Copy link

@mattlwilliams mattlwilliams commented Apr 27, 2017

I'm not the original reporter, but experienced this issue attempting to configure a build agent without Visual Studio - using https://aka.ms/vs/15/release/vs_buildtools.exe - excerpt from PS script:

&.\vs_buildtools.exe `
  --add Microsoft.VisualStudio.Workload.MSBuildTools `
  --add Microsoft.VisualStudio.Workload.WebBuildTools `
  --includeRecommended --includeOptional `
  --passive `
  --norestart
@frbar
Copy link

@frbar frbar commented Apr 28, 2017

Same here: that's ok with Enterprise VS 2017 on development machine, but nothing is published when running the same build command on a Jenkins box with the build tools (no VS installed).

@adam-knights
Copy link

@adam-knights adam-knights commented May 3, 2017

Very annoying issue, has anyone found a workaround when using TFS?

We have the VS 2017 build tools installed on our build agent and see this issue with publishprofile + DeployOnBuild=true

@ehaackXceligent
Copy link

@ehaackXceligent ehaackXceligent commented May 10, 2017

We can't move forward with msbuild 15 because of this.

@doughless
Copy link

@doughless doughless commented May 12, 2017

I had this issue even with VS 2017 Enterprise installed. I had to re-run the Enterprise installer and select the component "ASP.NET and web development tools" in order to get web publish to work from the build server. Now that I think about it, this seems very similar to a problem I had back around VS 2012/2013 that required the Azure SDK to be installed for web publish to work (even though I didn't need to install any Azure components this time around).

@ewilli
Copy link

@ewilli ewilli commented May 15, 2017

MSBuild 15.2 (26430.4) fixed the problem for me. (Just start the the installer; the update will then be available for install.)

@ehaackXceligent
Copy link

@ehaackXceligent ehaackXceligent commented May 15, 2017

This also fixes the issue (via Chocolatey) for versions prior to 15.2: https://chocolatey.org/packages/visualstudio2017-workload-webbuildtools

[Edit: clarification]

@ducseb
Copy link

@ducseb ducseb commented May 16, 2017

Same here, latest version of VS update fix the problem for me to.

@rainersigwald
Copy link
Contributor

@rainersigwald rainersigwald commented May 16, 2017

Glad to hear that updating seems to be working for folks. Please let us know if you're seeing this problem

  • After installing the Web Build Tools workload
  • On 15.2

If we don't hear a dissenting view, we'll close this as fixed . . .

@faemm
Copy link

@faemm faemm commented May 19, 2017

It's ok for me with latest VS Build Tools. Just take care of adding Web development build tools by modifying installation.

@Grandpappy
Copy link

@Grandpappy Grandpappy commented May 25, 2017

Had the same issue, and this worked for me. Something that confused me for a bit, is that the updater says 15.2 is installed, but the file version on MSBuild.exe is 15.1.1012.6693. I'm unsure if that's normal or not.

@rainersigwald
Copy link
Contributor

@rainersigwald rainersigwald commented May 25, 2017

@Grandpappy yes, that's the MSBuild version that shipped with VS15.2 (unchanged from 15.1).

@mInternauta
Copy link

@mInternauta mInternauta commented Jun 1, 2017

Hey Guys, I Tested the MSBuild for VS2017 Preview (15.3) and the problem still the same...

@emilegg
Copy link

@emilegg emilegg commented Jun 12, 2017

Hi, still have the same issue. :/

@RemSoftDev
Copy link

@RemSoftDev RemSoftDev commented Mar 1, 2018

same error. vs 2017 last update

@damtur
Copy link

@damtur damtur commented Mar 5, 2018

We're also having this problem which is preventing us from upgrading our build agents to handle mixed projects (.net core + framework 4.5.1). Can I kindly ask someone from Microsoft team to share any details if this is a known bug / new behaviour and if there are other ways to publish Webapp from msbuild in command lines?
Thank you!

@damtur
Copy link

@damtur damtur commented Mar 5, 2018

Update:
Adding
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" />
To csproj file made it work.

MSBuild version: 15.5.180.51428

@riezebosch
Copy link

@riezebosch riezebosch commented Mar 5, 2018

But I got it working even inside a docker container. For me the trick was installing the recommended components from the build tools installer:

& vs_buildtools.exe --quiet --wait --norestart --nocache --installPath C:\BuildTool `
    --add Microsoft.VisualStudio.Workload.WebBuildTools;includeRecommended `
    --add Microsoft.VisualStudio.Workload.MSBuildTools
@aliakseimaniuk
Copy link

@aliakseimaniuk aliakseimaniuk commented Mar 7, 2018

I'm using Visual Studio 2017 and have the same issue when I execute the following command

msbuild ./MyProject.csproj /p:DeployOnBuild=true /p:PublishProfile=DeployRelease /p:Configuration=Release

The problem was fixed when I executed script in the Developer Command Prompt VS 2017

@blkrishnan2k
Copy link

@blkrishnan2k blkrishnan2k commented Mar 9, 2018

I do have the same issue... Any solutions?

@blkrishnan2k
Copy link

@blkrishnan2k blkrishnan2k commented Mar 9, 2018

I wish to execute in a build server...

@mlorbetske
Copy link

@mlorbetske mlorbetske commented Mar 29, 2018

Adding @vijayrkn

@vijayrkn
Copy link

@vijayrkn vijayrkn commented Mar 29, 2018

You can find documentation on how to use PublishProfiles from commandline here - https://github.com/aspnet/websdk#folder-publish

Here is a sample project with a PublishProfile:
https://github.com/vijayrkn/dotnetpublishprofilesample/blob/7dac43543173b4ce908921106cc84d810c6dc623/WebPublishCommandlineSample/Properties/PublishProfiles/SampleFolderProfile.pubxml

MSBuild command to publish to a folder using the above publish profile: https://github.com/vijayrkn/dotnetpublishprofilesample/blob/7dac43543173b4ce908921106cc84d810c6dc623/PublishCommandline.txt

I would be happy to take a look at the issue if some one can provide me a sample project & msbuild command that is not working.

@IronSean
Copy link

@IronSean IronSean commented May 10, 2018

I'm also experiencing this. MSBuild 14 and 15. I used @rianjs's targets change in my process of fixing it, and now it works. But a minor issue: targets I build for the publish process execute during normal building now. Although this isn't a problem for me (it's just a webpack bundle I wanted to execute before publishing) it does slow down my builds that don't need to publish, and it could be a problem for others. I'm not sure why it's being triggered. BeforeTargets="PublishOnly" shouldn't really be happening on a normal build.

@brunoAmado
Copy link

@brunoAmado brunoAmado commented Jul 6, 2018

Using Visual Studio Build Tools 2017 (15.7.4) same problem. The project Build using Jenkins MsBuild plugin (and create a a file with the bin of the C# programme) but it doesn't publish multiple web-services related. Using Visual Studio IDE to publish works ok but want to automate the process if the publishing is Skipped.
Have some one have news to resolve that problem.

@dejoost
Copy link

@dejoost dejoost commented Jul 10, 2018

I'm not sure this is related but when trying to provide the PublishProfile it is ignored when defined within a custom target, specifying the properties directly in the project element is working

<Target Name="PublishProperties">
    <PropertyGroup>
      <PublishProfile>Package</PublishProfile>
      <DeployOnBuild>true</DeployOnBuild>
    </PropertyGroup> 
  </Target>
  <Target Name="Package" DependsOnTargets="PublishProperties" >
    <CallTarget Targets="Restore;Build"/> 
</Target>

EDIT: Fixed code example, still not working when I run:
msbuild /t:package

only works if I explicitly pass the profile through the command line:
msbuild /t:package /p:PublishProfile=Package

@admin-fsoft
Copy link

@admin-fsoft admin-fsoft commented Jul 11, 2018

Any movement or news from Microsoft on this or is Microsoft just gonna keep pretending this is not an issue? I provided a sample project & msbuild command that is not working a month ago and have not heard a single word back.

Pretty much until this issue is fixed, automated deployment is dead for anything that needs to transform a web config as a part of that deployment using the latest versions of MSBuild. So thanks guys, great job! ;)

You'd think that with all the releases for Visual Studio that MS puts out these days this issue would of been fixed by now. But nah, instead we got useless warnings instead like those ones about Resharper slowing down VS. This makes me wonder if this is nothing more than MS trying to keep people on Visual Studio by making it so you can only publish your applications via Visual Studio.

P.S. May I suggest that the MSBuild team incorporates some form of regression testing into their development cycle in order to not break existing features when making changes?

@noogen
Copy link

@noogen noogen commented Jul 11, 2018

@admin-fsoft I'm guessing it's probably very low priority as MS probably pushing everyone onto their cloud TFS and build.

@vijayrkn
Copy link

@vijayrkn vijayrkn commented Jul 11, 2018

@admin-fsoft - Sorry for not getting back to you sooner. I looked at the repro project that you shared. The issue is that the profile in the repro project only has 'LastUsedBuildConfiguration' property set (https://github.com/admin-fsoft/TestMSBuild/blob/3a1080e3b9d875083200da3cb592119e101c1b7b/TestMSBuild.Web/Properties/PublishProfiles/Release%20Deploy.pubxml#L10).

This property is only used by VS to determine which configuration to change to as part of publish. MSBuild does not know about this property. If you add the following property to the publish profile, then it would work from both VS and commandline.
<Configuration>Release</Configuration>

or you can pass this in the commandline - /p:Configuration=Release

The issue here is specific to configuration. You will notice that publish is honoring all other properties in the publish profile from the commandline (for e.g: it publishes to the publish folder specified in the profile).

Hope this helps!

@vijayrkn
Copy link

@vijayrkn vijayrkn commented Jul 11, 2018

There are a lot of other issues discussed here. Also the title seems to indicate that commandline publish is not honoring the profile at all. If you look at the repro project provided by @admin-fsoft (Thank you for providing the repro project) you will see that publish does honor the profile properties (for e.g: publishUrl, ExcludeApp_Data etc).

Configuration and Platform are a little different. You will have to either set them in the profile as Configuration and Platform or pass them from the commandline.

LastUsedBuildConfiguration and LastUsedPlatform are VS specific properties.

@admin-fsoft
Copy link

@admin-fsoft admin-fsoft commented Jul 12, 2018

Thank you for providing an answer and you are correct as this has resolved the problem with the provided test project.

I am now going to go and create a stack overflow question regarding exactly this and answer it so nobody else has to wait 1 month to get an answer. Thanks again.

@efunkenbusch
Copy link

@efunkenbusch efunkenbusch commented Oct 29, 2018

@vijayrkn - Visual Studio itself is creating that parameter in the publish profile, when you select the configuration to use. If this parameter should not be used, then this seems like a bug in VS.

@rafabaldoni
Copy link

@rafabaldoni rafabaldoni commented Dec 6, 2018

I was having this problem, and after trying a lot of different things I managed to solve it.

I'm using Build Tools(MSBuild v14.0) for building my project in a Jenkins job, and in my case the problem was that I was missing some Web Publishing Dlls.

I was able to get them from here: https://www.nuget.org/packages/MSBuild.Microsoft.VisualStudio.Web.targets/14.0.0.3

Putting them on the following directories solved my problem:
C:\Program Files(x86)\Microsoft\VisualStudio\v14.0\Web
C:\Program Files(x86)\Microsoft\VisualStudio\v14.0\WebApplications

@efunkenbusch
Copy link

@efunkenbusch efunkenbusch commented Dec 6, 2018

@rafabaldoni That wasn't it. For me, the problem was something specific in the csproj file. It was a very old .csproj and had been converted through several steps (I think it originally dates back to VS 2003). I ended up just creating a new default projects and copying all the files and settings to the new one. Then publish started working again.

@rafabaldoni
Copy link

@rafabaldoni rafabaldoni commented Dec 6, 2018

@efunkenbusch Yeah, maybe there are different problems that result in the same error... If someone is experiencing the same problem I had they might be able to solve it with my comment anyway.

@qcmiao1998
Copy link

@qcmiao1998 qcmiao1998 commented Dec 20, 2018

I meet the same problem.

@ericnewton76
Copy link

@ericnewton76 ericnewton76 commented Jan 7, 2019

There really is one core problem with the SDK and msbuild... there's zero accountability of dependencies

The csproj file since VS2010 is a mismash of msbuild targets that are yanked in via various ways, with zero dependency management.

Then when msbuild moves from v14 to v15, it all breaks again, because your csproj file doesnt know to say "hey, I need the targets file from Microsoft.NET.SDK.v14.xxxx" with a package manager (I keep hoping nuget will finally figure out how to do proper package dependency management but keep getting disappointed year after year)

Your core problem is usually this: Most of the time, your problem is missing Web.Application.targets file or a Web.Application.targets file that is a different version to what your csproj file is configured for. Not to mention, project upgrades in VS dont seem to deal with this, and leave the old configurations sitting around to muck up the new targets and again, we've traded DLL hell for TARGETS hell.

The answer has always been nuget to some degree, yet has been very slow to get integrated properly due to MS internal emp lack of understanding of whats going on out here, and the opaque nature at how it all worked for a while... with MS finally putting everything up on github, there's a lot more transparency and visibility, and people in the real world able to say "um, guys... that just doesnt make sense beyond basic assumptions"

@SirMrDexter
Copy link

@SirMrDexter SirMrDexter commented Feb 15, 2019

Found an alternative. Adding a FileSystemPublish task after Publish helps. My command looks something like this.
msbuild application.sln /t:"clean;publish;filesystempublish" /p:PublishProfile=folderprofile

@pmauri01
Copy link

@pmauri01 pmauri01 commented Sep 10, 2019

In my case I was dealing with an old web app that was created with an old version of VS I am guessing 2010 or 2012. It did not have project file, just a solution file. Same issue msbuild was ignoring the parameters when I passed the solution file as the parameter, so this is what I did....

msbuild website.publishproj /p:PublishProfile=OnCUWire_publish /p:DeployOnBuild=true /p:Configuration=Debug

website.publishproj is a file that VS created instead of the regular csproj. So by passing it to msbuild was able to publish it as the profile indicated.
I hope this helps

@livarcocc
Copy link
Contributor

@livarcocc livarcocc commented Sep 11, 2019

I am going to close this issue as there are many different conversation going on here and I believe the original question has been addressed by Vijay earlier in the thread.

@livarcocc livarcocc closed this Sep 11, 2019
@RichardsonWTR
Copy link

@RichardsonWTR RichardsonWTR commented Jun 26, 2020

First, thank you @richardszalay
I struggled to find a solution, until I found this answer on Stack Overflow: How to use MsBuild MsDeployPublish to target local file system?

Quoting the answer of the link above:

As per my answer from Using MSBuild, how do I build an MVC4 solution from the command line (applying Web.config transformations in the process) and output to a folder?

msbuild ProjectFile.csproj /p:Configuration=Release ^
                           /p:Platform=AnyCPU ^
                           /t:WebPublish ^
                           /p:WebPublishMethod=FileSystem ^
                           /p:DeleteExistingFiles=True ^
                           /p:publishUrl=c:\output

Or if you are building the solution file:

msbuild Solution.sln /p:Configuration=Release ^ 
                     /p:DeployOnBuild=True ^
                     /p:DeployDefaultTarget=WebPublish ^
                     /p:WebPublishMethod=FileSystem ^
                     /p:DeleteExistingFiles=True ^
                     /p:publishUrl=c:\output

You can also target the project via the solution using the /t:SolutionFolder/Project:Target syntax:

msbuild Solution.sln /t:SolutionFolder/ProjectFile:WebPublish ^
                     /p:Configuration=Release ^ 
                     /p:WebPublishMethod=FileSystem ^
                     /p:DeleteExistingFiles=True ^
                     /p:publishUrl=c:\output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet