Razorlight: Intellisense is not working for View Template file. Yes I am inheriting from TemplatePage

Created on 7 Feb 2019  路  6Comments  路  Source: toddams/RazorLight

Describe the bug
Intellisense is not working for View Template file. Yes I am inheriting from TemplatePage

image

To Reproduce
Create a Project with the following

Project file

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="TestView.cshtml" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="TestView.cshtml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="RazorLight" Version="2.0.0-beta1" />
  </ItemGroup>

</Project>

TestView.cshtml

@using QuestionRazorLight
@using RazorLight
@inherits TemplatePage<TestViewModel>

<table id="myTable" class="table" cellspacing="0">
    <thead>
        <tr>
            item1
        </tr>
        <tr>
            item2
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model.listOfStuff)
        {
            <tr>
                item.item1
            </tr>
            <tr>
                item.item2
            </tr>
        }
    </tbody>
</table>

TestViewModel.cs

using System;
using System.Collections.Generic;
using System.Text;

Program.cs

using System.Collections.Generic;
using System.IO;
using System.Reflection;
using RazorLight;

namespace QuestionRazorLight
{
    class Program
    {
        static void Main(string[] args)
        {
            var viewmodel = new TestViewModel
            {
               listOfStuff = new List<(string, string)>() { ("Blah1","blah1"), ("Blah2", "blah2") }
            };


            var engine = new RazorLightEngineBuilder()
              .UseFilesystemProject(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
              .UseMemoryCachingProvider()
              .Build();

            string reportAsHTML = engine.CompileRenderAsync($"{Path.DirectorySeparatorChar}TestView.cshtml", viewmodel).Result;
        }
    }
}
namespace QuestionRazorLight
{
    public class TestViewModel
    {
        public IList<(string,string)> listOfStuff { get; set; }
    }
}

Expected behavior
I expect there not to be any syntax errors about missing AspNetCore assemblies

Information:

  • OS: Windows 10 1809
  • Visual Studio Community 2017 (15.9.4)
  • Platform .NET Core 2.1
  • RazorLight version 2.0-beta1

Additional Information
This will compile and run but I can't figure out how to make the syntax errors go away.

Investigate

Most helpful comment

You can try to add PackageReferences to your Project file
```

<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="2.1.0" />

```

All 6 comments

Nobody?

image

Here we go again, I'm sick and ready for work :D
Investigating possible issue

Any ideas?

You can try to add PackageReferences to your Project file
```

<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="2.1.0" />

```

@TheColonel2688

Add 'Web' to the end of your project sdk, that wakes the intellisense up.


netstandard2.0

Library

Closed thanks to @billrob

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dombarnes picture dombarnes  路  7Comments

IInvocation picture IInvocation  路  6Comments

Wolftousen picture Wolftousen  路  5Comments

Eonasdan picture Eonasdan  路  6Comments

btran021111 picture btran021111  路  4Comments