Saturday, March 26, 2016

When deploying DNX projects to Azure, some times we may get the error saying that "File Path too long"

When deploying DNX projects to Azure, some times we may get the error saying that "File Path too long".

When I am deploying the DNX project to Azure, I got the below error

The "Dnu" task failed unexpectedly.
System.Exception:
Microsoft .NET Development Utility Clr-x86-1.0.0-rc1-16231
Copying to output path C:\Users\v-lapedd\AppData\Local\Temp\PublishTemp\Microsoft.Legal.MatterCenter.Service116

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.
   at Microsoft.DNX.Tasks.Dnu.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()


The reason for this is, by default Visual Studio will use the below directory
"C:\Users\v-lapedd\AppData\Local\Temp\PublishTemp" to create the package and from there deploy the file to Azure.

Sometimes, the path of the deployed package will be such that it will exceed NTFS file system path limit which is 248.

If you look into that folder structure of the PublishTemp folder and the approot in that folder and the Packages in that folder, it contains all the packages that are used in your project.

Sometimes the package folder will be long based the namespace of the project. For ex, there is one nugget package with in the deploy folder which is more than 248 characters


C:\Users\profilename\AppData\Local\Temp\PublishTemp\Microsoft.Legal.MatterCenter.Service116\approot\packages\Microsoft.Extensions.Configuration.EnvironmentVariables\1.0.0-rc1-final\lib\dotnet5.4\Microsoft.Extensions.Configuration.EnvironmentVariables.dll
 
 
 
Solution
One solution to this one will be, controlling the publish folder path. Instead of publishing the project to default path which visual studio uses, if we publish to any path which is short, then this issue will be solved.

How to change the project deployment path of DNX or Asp.Net Core 1.0 project?

Here are the steps:

1. Open the project (xproj) that you want to deploy to Azure or to any other location in any text editor

2. Then add the below xml code below the node

 
 


Note: Take care that there are no training "\" at the end of the folder path that you have given. If there is any trailing "\", you will get the error saying that, "Illegal Characters in the path"

Correct path: C:\Temp\Publish

Wrong path: C:\Temp\Publish\

3. Save the project file

4. Open the solution again in visual studio and publish the file and the project and this time the publish should succeed


Here is the modified xproj file


  
  
  
    
    
    
  

 

1 comment:

  1. I recommend you to try Long Path Tool program to fix this problem

    ReplyDelete