Code Exchange between an ASP.NET MVC Project and a Cordova Project

I am developing a Cordova-based mobile application using the Visual Studio Cordova template, as well as an ASP.NET MVC web application in the same Visual Studio solution. I would like to be able to share as much HTML as possible between both projects. One of the problems that I am facing is combining and minimizing that happen in ASP.NET that are not available in the Cordova project. Any ideas on how I could support minimization in Visual Studio on both projects that would allow me to use as much code as possible?

+5
source share
1 answer

The Cordova .jsproj project .jsproj is a regular assembly file that is processed by MSBuild, so you can apply any processing logic by adding custom targets. You can even run tools from the world of Node.js, such as Grunt or Gulp, by installing the appropriate VS extensions.

Regarding code sharing between ASP.NET and Cordova projects, I suggest adding links to your .jsproj as follows:

 <PropertyGroup> <AspNetProject>C:\YourAspNetProject</AspNetProject> </PropertyGroup> <ItemGroup> <Content Include="$(AspNetProject)\Views\**\*.cshtml"> <Link>views\%(RecursiveDir)%(FileName).html</Link> </Content> <!-- add other links here --> </ItemGroup> 

In this way, VS displays related files in Solution Explorer and allows you to edit them as if they were local.

Unfortunately, the current version of VS Tools for Apache Cordova, CTP3, does not support related items, so in your .jsproj you need to make the following change:

 <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CordovaTools\vs-mda-targets\Microsoft.MDA.targets" /> <PropertyGroup> <BuildDependsOn>PreBuild;$(BuildDependsOn)</BuildDependsOn> </PropertyGroup> <Target Name="PreBuild"> <ItemGroup> <LinkedFiles Include="@(Content)" Condition="'%(Content.Link)' != ''" /> <!-- add other links here --> </ItemGroup> <Copy SourceFiles="%(LinkedFiles.Identity)" DestinationFiles="%(LinkedFiles.Link)" /> </Target> 

The PreBuild task PreBuild called before any Build subtask and copies the related files to your project in Cordoba. The rest of the build process runs as usual.

0
source

Source: https://habr.com/ru/post/1204596/


All Articles