<Target Name="CopyToDeployFolder" DependsOnTargets="CompileWebSite"> <Exec Command="xcopy.exe $(OutputDirectory) $(DeploymentDirectory) /e" WorkingDirectory="C:\Windows\" /> </Target>Namedoesn't matter, it is DependsOnTargets that is important.
Tuesday, May 28, 2013
MSBuild Publish target for LocalEnvironment configuration (why BeforePublish and AfterPublish was not triggered)
The best way to debug msbuild, or to find what targets and tasks are triggered, and where can you hook up, is to ask msbuild to be more verbose (under VS tools->options). After looking at what targets are executed when publishing application from within VS by using Local Environment as a publish method, one can see that BeforePublish and AfterPublish was never triggered. But you can start using any target that you can see in log to do desired operation. For example, if I want to do something after CompileWebSite target is finished running I just write something like:
Access denied problem is a most typical problem for me when setting new application under IIS. The most typical example that I see recently in various environments is related to understanding of what users accounts are used under a hood. Namely that sometimes there is a need to assign permissions on a hard drive not for one user but for two of them. Consider that you set up application pool identity to Network Service, it is a common mistake to believe that this is the only user that you need to grant a permission to application folder. Unfortunately if application allowed anonymous users, they also run in a context of a user account, and by default in IIS 7.5 it is set to IUSR account. It means that you need to set up permissions also for this user on a hard drive.