0

I need to publish a .NET web site project to a local directory. The web site project is part of a solution that also contains a web app. The Publish Web App option in Visual Studio publishes the web site to the directory without issue, however I am unable to publish the site through msbuild.

My msbuild command

msbuild "C:\...\ProjectName\website.publishproj" /p:deployOnBuild=true /p:publishProfile=Dev /p:PrecompileBeforePublish=false /p:VisualStudioVersion=14.0 /p:WebPublishMethod=FileSystem

The dev.pubxml publish profile I am referencing is:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>True</ExcludeApp_Data>
    <publishUrl>C:\FolderLocation</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
    <ExcludeFoldersFromDeployment>.vs</ExcludeFoldersFromDeployment>
  </PropertyGroup>
</Project>

Currently the web site is not publishing to C:\FolderLocation but instead appears to publish to ProjectName\PrecompiledWeb\localhost_51636. Changing the output directory via /p:OutDir=C:\FolderLocation publishes the web app to the correct location, however it does not publish the web site. I have also tried both /p:PublishDestination and /p:DesktopBuildPackageLocation msbuild arguments however the original issue remains.

I have referenced Publish Artifacts for website goes to PrecompiledWeb and many other resources. My eventual goal is to setup CI through Azure Devops for the entire legacy .NET website project.

pirateofebay
  • 930
  • 1
  • 10
  • 25
  • Where do you run the msbuild? I mean, do you use developer command prompt for vs2015 or use 'cmd+msbuild.exe under v4.0.30319' folder? Cause I've test with leo's answer, and that command works well on my side with VS2015 website. – LoLance Mar 22 '19 at 05:52
  • Hi friend, when you mentioned "publish the site through msbuild", do you mean the issue occurs when using the msbuild tool locally without TFS. – LoLance Mar 22 '19 at 05:59
  • Hi Lance. I am running msbuild locally from `C:\Windows\Microsoft.NET\Framework\v4.0.30319`. When I use Leo's command, the command completes but it does not publish to the directory listed in my dev.pubxml publish profile. It appears to be publishing to `ProjectName\PrecompiledWeb\localhost_51636` instead. – pirateofebay Mar 22 '19 at 18:44
  • Hi, friend, try open the developer coomand compt for vs2015, and type the command there. I've seen many issues with the msbuild.exe under v4.0.30319 folder. Please try the C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe.(This version is more suitable for you) – LoLance Mar 23 '19 at 12:08
  • And for leo's command. We all use the developer command prompt to run the command, and we all succeed. (Instead of v4.0.30319, I think it's not latest version for vs2015) – LoLance Mar 23 '19 at 12:10
  • Try using command: msbuild ... /p:publishUrl=C:\FolderLocation. I doubt whether the content of publish profile is read, so you can use this property to try to overwrite it. – LoLance Mar 28 '19 at 03:18

1 Answers1

0

With TFS - it is using MSBUILD under the covers and we need this parameter to write to a directory for artifacts to be pulled from

/p:OutDir=$(build.StagingDirectory)

You are telling it only about the Publish Project part - see if putting your SLN file there at the first parameter solves it and does all of them.

Mark W. Mitchell
  • 749
  • 1
  • 6
  • 8
  • Thanks for your suggestion. I have also tried building the .SLN instead, however this creates a new issue. The web app is published to `C:\FolderLocation\Projectname\_PublishedWebsites` and the web site becomes published to a new directory location `C:\ProjectName_PublishedWebsites`. – pirateofebay Mar 21 '19 at 21:09
  • Yes - and then you navigate down that structure for what you want to be in your virtual directory and push it in. – Mark W. Mitchell Mar 21 '19 at 21:41
  • Thank you Mark, I am able to start the website from within that directory. I am still confused why msbuild ignores the output directory from `dev.pubxml` using the original command I linked to above. To setup a CI server using the method you've provided would require additional copy commands and be messy to automate. – pirateofebay Mar 22 '19 at 21:00
  • Looks like you need to be on Visual Studio version 15.2 (Visual Studio 2017 update 2) based on this discussion https://github.com/Microsoft/msbuild/issues/1901 – Mark W. Mitchell Mar 23 '19 at 15:11