简体   繁体   中英

How to publish an asp.net mvc 4 application with areas?

I have a asp.net mvc 4 application that has multiple area setup. However, this application uses multiple projects to make up this area as explained here to follow n-tier in the solution. The output path of these separate projects is set to the bin folder of the main mvc application which works fine.

When I publish this main app on file system as target, the Areas folder that is created in the directory only has HelpPage folder content but no area folders.

I would like to know how can I add their resources like views, .config files, scripts, content, etc. to the Areas folder on publish.

At the moment I'm doing this using a bat file which I think is not appropriate. I've read about using [ProjectName].wpp.targets to include files while publishing. Can anyone advice how to include folders which is not included in the project, different areas in this context.

We're using the same project set up as the blog post you provided. In our case we ended up adding [ProjectName].wpp.target with the following content..

<Target Name="CopyCustomFiles" AfterTargets="CopyAllFilesToSingleFolderForPackage" >   
     <ItemGroup> 
         <Areas Include="$(ProjectDir)Areas\*\Content\**;$(ProjectDir)Areas\*\Images\**;$(ProjectDir)Areas\*\Scripts\**;$(ProjectDir)Areas\*\Views\**;$(ProjectDir)Areas\*\web.config;$(ProjectDir)Areas\*\*.xml"  />
        </ItemGroup>

      <Copy SourceFiles="@(Areas)" DestinationFiles="@(Areas->'$(_PackageTempDir)\areas\%(ToPath)\%(RecursiveDir)%(Filename)%(Extension)')" />

</Target>

Basically the goal was the include the custom files in the msbuild publishing pipelines and by using "CopyAllFilesToSingleFolderForPackage", we're doing exactly that. Another approach would be to have a dedicated msbuild script, check the answer here How to Publish Web with msbuild?

Having a bat file, just like yours works too...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM