VirtualPath in AspNetCompiler MSBuild Task - does it have to be equal to the final deployed Virtual Path?
This is VS 2008 and .Net 3.5.
I use a custom deployment proje开发者_运维知识库ct script which is similar to the publish right-click menu, but which I have customised to do file renaming and various other bits and pieces. It works really well and has drastically simplified the release procedure.
I was made aware of an issue on one of our live sites this weekend that would have been prevented had the site been precompiled (long story).
So I've been playing around with injecting the AspNetCompiler MSBuild Task (using the PhysicalPath attribute to direct towards the intermediate publish folder) into the deployment script and I have a question regarding the 'VirtualPath' option.
Despite the fact that the website is not in IIS at this pre-deploy stage, you are still required to provide a value for the 'VirtualPath' attribute. I have seen here that the associated -v switch on aspnet_compiler.exe uses this value in resolving '~' rooted virtual paths used throughout the site during the compilation.
So, I take this to mean that whatever you pass here must be the virtual root of the application when deployed otherwise it won't work.
However, I've tried this out, passing something like '/fake/fake' in this option and then changing one of my master pages to reference a css via an app-rooted url instead of relative, and it still worked even when deployed to a virtual path of '/site' and not '/fake/fake'.
So what's the definitive answer on this? Do I need to worry about this VirtualPath value being exactly equal to the eventual deployed location of a site in IIS? I hope not, because I don't really want my deploy project to have any knowledge of the virtual hierarchy of the target web server, in case it needs to change.
I've analyzed the code that is precompiled and it would seem that the precompiler automatically resolves the application-rooted paths to relative paths anyway, regardless of what you set the VirtualPath too. I've also tried deploying the same pre-compiled site to different virtual paths on the target server and nothing breaks.
So therefore I'm confident enough to be able to say: no it does not matter what this value is.
No doubt there's bound to be something I've potentially missed - but until I'm proved wrong I'll assume I'm right!
精彩评论