Q:

Wrong --out in TFS 2015 dnu publish

When i try to publish my asp.net core webapplication in TFS 2015 it fails the build task with "DNU(0,0): Error : The specified path, file name, or both are too long".
When troubleshooting i realized that the dnu.cmd publish had the following parameters:

C:\Windows\ServiceProfiles\NetworkService.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin\dnu.cmd
  publish "D:\TFSAgent_work\19\s\code\src\WebsiteApp" --out
  "C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\PublishTemp\WebsiteApp59"
  --configuration Release --runtime dnx-clr-win-x86.1.0.0-rc1-update1 --wwwroot "wwwroot" --wwwroot-out "wwwroot" --iis-command "web"

The MSBuild arguments in TFS is set to:

/P:PublishProfile=PubStaging /P:DeployOnBuild=True

So the build fails when copying files:

Using Package dependency Microsoft.AspNet.Http.Features
  1.0.0-rc1-final
               Source C:\Windows\ServiceProfiles\NetworkService.dnx\packages\Microsoft.AspNet.Http.Features\1.0.0-rc1-final
               Target C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\PublishTemp\WebsiteApp59\approot\packages\Microsoft.AspNet.Http.Features\1.0.0-rc1-final
DNU(0,0): Error : The specified path, file name, or both are too long.
  The fully qualified file name must be less than 260 characters, and
  the directory name must be less than 248 characters.

The TFS server is running under the NetworkService, but the output should go into "....\artifacts\PublishOutput" according to my publish profile.
Can anyone give me a hint how to proceed?

A:

Check this case:

Powershell script "prebuild.ps1" as per the previous answer and Microsoft deployment guidelines: https://msdn.microsoft.com/en-us/Library/vs/alm/Build/azure/deploy-aspnet5
Vanilla MSBuild build. no switches or special settings.
Powershell script to run "dnu publish". This creates a directory of the entire web application's structure.
"Windows File Copy" task to deploy the directory structure created in #4 to all of the target machines in the test environment.

