I am using a hosted build agent on VSTS, to build and deploy a Cloud Service.
When packaging the Cloud Service, cspack.exe complains that it cannot find the physical directory for a virtual path.
....
<WebRole name="MySite" vmsize="Small">
<Sites>
<Site name="Web">
<VirtualDirectory name="media" physicalDirectory="Z:\MySiteMedia" />
<Bindings>
....
ServiceDefinition.csdef: Error CloudServices079 : Cannot find the physical directory 'Z:\MySiteMedia' for virtual path Web/media/.
It is true that the physical directory does not exist on the build server, but it exists on the server that the Cloud Service is going to be deployed to. It's an Azure File Share.
Is there a workaround?
Update
It is possible to create a virtual drive on the build agent, which has the required drive letter and folder. The drive could be pointing to another local drive. For intance, Z:\ could be pointing at C:\
Example:
net use Z: \\localhost\c$\MySiteMedia
This fixes the build issue, however, it doesnt solve the actual problem.
After some digging, I found out that cspack does not work as I originally thought. When adding a
<VirtualDirectory>
to the ServiceDefition, it takes the contents of that folder and packages it in the cspkg file. Then it creates a new folder, which it places in the siteroot folder, and then creates a virtual directory to that new folder.
Example:
Becomes
Which means that the Azure File Share on Z:\ will not be used.
The workaround is to create add the virtual directory to IIS after the role has been deployed, by using a RoleEntryPoint.