Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

How to publish console app as a WebJob rather than Web App #7677

Closed
Liero opened this issue Apr 18, 2018 · 6 comments
Closed

How to publish console app as a WebJob rather than Web App #7677

Liero opened this issue Apr 18, 2018 · 6 comments
Labels

Comments

@Liero
Copy link

Liero commented Apr 18, 2018

Hi,
I have a console app that I want to deploy as web job. It's based on Entropy/samples/Mvc.RenderViewToString/ sample.

The problem is, that is uses Microsoft.NET.Sdk.Web rather than Microsoft.NET.Sdk in order to render the razor views although it is not web application.

When I invoke the publish dialog, it publishes it as web app, not as web job. When I replace Microsoft.NET.Sdk.Web with Microsoft.NET.Sdk, it shows the correct web job publish dialog, but then I get runtime exception when I try to invoke the razor view.

<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <LangVersion>latest</LangVersion>
    <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
    <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\DataAccess\TACS.DataAccess.csproj" />
  </ItemGroup>

  <ItemGroup>
    <None Include="appsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="Settings.job">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="MyProject.ReminderWebJob.cmd">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Properties\" />
    <Folder Include="Properties\PublishProfiles\" />
  </ItemGroup>
</Project>
@mkArtakMSFT
Copy link
Member

Hi @Liero.
What are you trying to do? WebJobs supposed to be running in background and have no UI.
Why are you trying to do that?

@Liero
Copy link
Author

Liero commented Apr 20, 2018

@mkArtakMSFT:
In fact, I do have an application, that is supposed to be running on the background without UI, just like the Mvc.RenderViewToString sample does, but I'm forced to use the Web SDK anyway in order to make it work.

My WebJob is supposed to send email reminders in background, but in order to use Razor as "mail templates" I had to reference the web sdk

@mkArtakMSFT
Copy link
Member

@pranavkm, can you please look into this one? Thanks!

@pranavkm
Copy link
Contributor

but then I get runtime exception when I try to invoke the razor view.

What's the exception you're seeing? You likely need to set <PreserveCompilationContext>true</PreserveCompilationContext> in your app - my guess is Razor compilation cannot find reference assemblies to compile against.

@Liero
Copy link
Author

Liero commented Apr 23, 2018

@pranavkm, you are right about the exception and setting PreserveCompilationContext does help indeed.

This solves my situation (feel free to close the issue), but:

  1. it's still unclear to me, why project using Microsoft.NET.Sdk cannot compile the views without PreserveCompilationContext and Microsoft.NET.Sdk.Web can. What are side effects of PreserveCompilationContext.

  2. are you sure that the project SDK should determine how the app will be published? If yes, it would be good to have an workaround.

@pranavkm
Copy link
Contributor

  1. PreserveCompilationContext results in the app including reference assemblies in the output along with metadata in the deps file. The side effect is a larger deploy\publish size. These are only ever required if you're doing runtime compilation. Most desktop applications don't do this, which is why you it's only enabled by default by the Web Sdk.

are you sure that the project SDK should determine how the app will be published?

The Web.Sdk is opinionated about the kind of target you're deploying it and shows a dialog best suited for their targets. Not sure if there's a way to change this behavior - you could try asking at https://github.com/aspnet/websdk.

@Liero Liero closed this as completed Apr 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants