-->

How to publish an asp.net mvc 4 application with a

2019-09-06 18:53发布

问题:

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.

回答1:

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...