locked
How to generate Pre Compiled views through command line/ MS build in Code first Approach. RRS feed

  • Question

  • I want to automate my Publish work through MS build. My project is using code first approach and I need to generate the pre-compiled / pre-Generated views prior to deployment. In visual studio, I was doing this using a tool called - ASP.NET C# web site Entity Generator. While browsing on the net, I found a way through EdmGen.exe. But in this approach, it asks for three files - .csdl, ssdl and .msi which are generated if I had used .edmx file instead of Code first Approach. But I want to achieve this in Code First Approach itself.
    Tuesday, March 5, 2013 5:26 AM

Answers

  • Hi,

    Please view this article below to learn more about publish a web site with MSBuild:

    http://codingcockerel.co.uk/2008/05/18/how-to-publish-a-web-site-with-msbuild/

    If you want to compile Apps your way with custom tasks, you can view:

    http://msdn.microsoft.com/en-us/magazine/cc163589.aspx

    Best regards,


    崖山之後無中國,明亡之後無華夏

    • Proposed as answer by Ego Jiang Tuesday, March 12, 2013 1:34 AM
    • Marked as answer by Ego Jiang Tuesday, March 12, 2013 1:43 AM
    Wednesday, March 6, 2013 6:01 AM
  • Thanks Disley of your post. I had already viewed those links. This links helped a bit but not completely.

    But I will tell all know how solved this problem.

    1. I created the edmx file though my Repository.cs through a unit test. (Assuming: Any Pre-Required code generation is done). This is how it is done:

      

    XmlTextWriter writer = newXmlTextWriter(Path.Combine(DomainDir, "Repository.edmx"), Encoding.UTF8); EdmxWriter.WriteEdmx(this.repository, writer);

    2. Then I ran that Test using mstest.exe through Msbuild.

    <Exec Command="mstest /testcontainer:&quot;$(SolutionDir)\TestProject\bin\Release\Test.dll&quot; /test:CreateEdmx" />		
    

    2. I Then Build the project where my Repository.cs file and edmx files resides. This created the three files required for generation of pre-generated views namely .csdl, .ssdl and .msi.

    3. Then using this in MSBuild Project file

    <Exec Command="%windir%\Microsoft.NET\Framework\v4.0.30319\EdmGen.exe /nologo /language:CSharp /mode:ViewGeneration &quot;/inssdl:$(SolutionDir)\ProjectFolder\obj\Release\edmxResourcesToEmbed\Repository.ssdl&quot; &quot;/incsdl:$(SolutionDir)\ProjectFolder\obj\Release\edmxResourcesToEmbed\Repository.csdl&quot; &quot;/inmsl:$(SolutionDir)\ProjectFolder\obj\Release\edmxResourcesToEmbed\Repository.msl&quot; /outviews:$(SolutionDir)\ProjectFolder\Repository.Views.cs" /> 

    N.B.

    I had a dummy .edmx is already in the TFS and checked out .edmx and Repository.cs file before using this steps. The .edmx file will be updated every time we create that file. 

    I have tried to explain the steps based on my project. Please let me know if somebody don't get what I meant.

    Regards,

    Brijesh Gupta.

    • Marked as answer by Brijesh G Friday, March 15, 2013 11:36 AM
    Friday, March 15, 2013 11:33 AM

All replies

  • Hi,

    Please view this article below to learn more about publish a web site with MSBuild:

    http://codingcockerel.co.uk/2008/05/18/how-to-publish-a-web-site-with-msbuild/

    If you want to compile Apps your way with custom tasks, you can view:

    http://msdn.microsoft.com/en-us/magazine/cc163589.aspx

    Best regards,


    崖山之後無中國,明亡之後無華夏

    • Proposed as answer by Ego Jiang Tuesday, March 12, 2013 1:34 AM
    • Marked as answer by Ego Jiang Tuesday, March 12, 2013 1:43 AM
    Wednesday, March 6, 2013 6:01 AM
  • Thanks Disley of your post. I had already viewed those links. This links helped a bit but not completely.

    But I will tell all know how solved this problem.

    1. I created the edmx file though my Repository.cs through a unit test. (Assuming: Any Pre-Required code generation is done). This is how it is done:

      

    XmlTextWriter writer = newXmlTextWriter(Path.Combine(DomainDir, "Repository.edmx"), Encoding.UTF8); EdmxWriter.WriteEdmx(this.repository, writer);

    2. Then I ran that Test using mstest.exe through Msbuild.

    <Exec Command="mstest /testcontainer:&quot;$(SolutionDir)\TestProject\bin\Release\Test.dll&quot; /test:CreateEdmx" />		
    

    2. I Then Build the project where my Repository.cs file and edmx files resides. This created the three files required for generation of pre-generated views namely .csdl, .ssdl and .msi.

    3. Then using this in MSBuild Project file

    <Exec Command="%windir%\Microsoft.NET\Framework\v4.0.30319\EdmGen.exe /nologo /language:CSharp /mode:ViewGeneration &quot;/inssdl:$(SolutionDir)\ProjectFolder\obj\Release\edmxResourcesToEmbed\Repository.ssdl&quot; &quot;/incsdl:$(SolutionDir)\ProjectFolder\obj\Release\edmxResourcesToEmbed\Repository.csdl&quot; &quot;/inmsl:$(SolutionDir)\ProjectFolder\obj\Release\edmxResourcesToEmbed\Repository.msl&quot; /outviews:$(SolutionDir)\ProjectFolder\Repository.Views.cs" /> 

    N.B.

    I had a dummy .edmx is already in the TFS and checked out .edmx and Repository.cs file before using this steps. The .edmx file will be updated every time we create that file. 

    I have tried to explain the steps based on my project. Please let me know if somebody don't get what I meant.

    Regards,

    Brijesh Gupta.

    • Marked as answer by Brijesh G Friday, March 15, 2013 11:36 AM
    Friday, March 15, 2013 11:33 AM