Wednesday, February 21, 2018

Publish (FTP) fails from MSBUILD

Leave a Comment

If I publish with my website with Visual Studio (using FileSystem) it works fine.

Now I'm attempting to do the same from Powershell.

.\MSBuild.exe $sln /p:PublishProfile=MyTestProfile /p:PublishProvider=FileSystem /p:CreatePackageOnPublish=False /p:DeployOnBuild=False /p:VisualStudioVersion=15.0 /v:diag 

The above is based upon the output window (of Visual Studio) when I publish (using diagnostic output). Things are copied and pasted to avoid typos.

The problem I have is it never publishes!

I am now shown the following message from Powershell:

Build FAILED.

"C:\Users\me\source\repos\Test03\WebApplication2\WebApplication2.csproj" (default target) (1) -> C:\Users\me\source\repos\Test03\WebApplication2\WebApplication2.csproj(265,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

This issue appears to be well documented here on SO but, I already have VS installed, and this isn't a build server. It's all being done on my one machine... However, if I try to get to the path C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets it doesn't exist. I have C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\ but within this folder only 1 folder called FileTracker.

This now confuses me more because it works from within Visual Studio, but not within Powershell.

1 Answers

Answers 1

Resolved with

.\MSBuild.exe $sln /p:PublishProfile=MyTestProfile /p:PublishProvider=FileSystem /p:CreatePackageOnPublish=False /p:DeployOnBuild=True /p:AspnetMergePath="C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools" /p:VisualStudioVersion=15.0 #/v:diag 

You may not have the path for the correct visual studio version. Downloading .NET Core SDK should provide this https://www.microsoft.com/net/download/windows

However, you may need to update to the correct path for the build path (where msbuild.exe exists).

I then had to add /p:AspnetMergePath="C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools" manually for reasons I don't understand. I understand that it coudln't find this path, but I didn't understand why it can't find the path when VS could!

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment