.Net Core View: the name "Layout" does not exist in the current context - asp.net-core

I'm using Visual Studio 2017 to build a .net core mvc project.
When I add a view in this way:
Right click folder -> Add View -> Add
Then the name "Layout" does not exist in the current context
Restart vs or build the project this error still exist.
However, If I add view in this way:
Right click folder -> Add New Items -> MVC View Page
the Layout can be recognized.
Is there any difference?

If you are using vs 2017 you have to add this code in new csproj which you created.
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>
Because When you create a new Web application, this gets set to the "Web" SDK:
<Project Sdk="Microsoft.NET.Sdk.Web">...</Project>
so the Web SDK imports additional tasks to allow design-time processing of Web resources, such as Razor views. Change the SDK in your plugin library to Web.
after you build error should be vanished.

Related

Web deployment package: Skip files when deploying

I want to create a web deployment package which leaves certain existing directories alone when deploying, e.g. a "logs" folder. Currently the package deletes/overwrites all existing files.
I can exclude the folder by adding extra parameters when executing the foo.deploy.cmd in the package, eg.:
.\foo.deploy.cmd /T """-skip:Directory=\\logs"""
This seem to work. But I can't figure out how to include this configuration in the package itself so it will be applied automatically.
I have a Asp.net Core website on .net framework 4.7. I use Visual studio 2019 with a pubxml publish profile.
I have tried adding MsDeploySkipRules to the pubxml but they don't seem to be passed to the package parameters. I am unsure if MsDeploySkipRules should work with "Web Deploy Package" or only with "Web Deploy"?
Edit: The problem may be related to I'm using Asp.net core. The MsDeploySkipRules seem to be applied in a regular asp.net (added in the generated deploy.cmd script) project but not if I insert the same in an asp.net core project file.
You could try to add the below code in your .csproj file to skip the folder at the time of publishing.
<ItemGroup>
<Content Remove="wwwroot\test\**" />
</ItemGroup>
also ste the delte existing file to true:
ASP.NET Core: Exclude or include files on publish

When embedding .cshtml files, there are errors parsing the files (types cannot be found)

I had moved a project over from VS 2015 to VS 2017, and while editing the assembly with the embedded views, I noticed things like "#addTagHelper" and "#using" were failing, and not highlighting properly. How can I edit my embedded views like my main web project?
Turns out, if you are using Visual Studio 2017, you need to make sure these lines are in your project file for the assembly with the embedded views:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
...etc...
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
By default, the project is set to sdk="Microsoft.NET.Sdk". Once this is changed, and PreserveCompilationContext added, the views should compile and highlight properly in the editor. You may also need to right click on the project, edit the settings, and set Output type: to Class Library (it was Console Application by default for me).

How to add new item to .net-core project in macOS

I am new in .net core.
I created my new empty project with this command :
dotnet new web -n MyTestApp
if it is right?
Then i added a new folder called Controllers, and now i want to add new
HomeController.cs
to this folder, i want to know how?
In Visual Studio simply i right click on Controllers folder and add new item to this folder, but in Visual Studio Code as you know we don't have New Item menu.
Just add it to your project directory.
In net core you don't need to list each project file in your csproj or project.json.

ASP.NET 5 System.Runtime.Caching

I am converting an existing .Net 4.5 MVC 5 project to a new ASP.NET 5 project. One of my files is referencing the System.Runtime.Caching namespace but on moving this file to the new project this namespace cannot be found.
I have added System.Runtime as a dependency in the new project, but the .Caching bit seems to be missing from this. Has anybody experienced a similar problem?
You need to bring in 'Microsoft.Extensions.Caching.Memory' using the following line in your project JSON.
"dependencies": {
"Microsoft.Extensions.Caching.Memory": "1.0.0"
}
Current documentation can be found here.
https://docs.asp.net/en/latest/performance/caching/memory.html
To use the System.Runtime.Caching namespace in an ASP.NET application, you must add a reference to the namespace.
To add a reference to the Website
In Solution Explorer, right-click the name of the Web site and then
click Add Reference.
Select the .NET tab, select System.Runtime.Caching, and then click
OK.
Ref: https://msdn.microsoft.com/en-us/library/ff477235(v=vs.110).aspx#Anchor_2

TFS 2010 - WebDeployment - indirect referenced assembly missing

We've got the following problem:
solution-structure:
AutofacRegistration
References: Repositories.dll
WebApplication
References: AutofacRegistration.dll
In our web application we are referencing the AutofacRegistration.dll and this assembly references Repositories.dll. Repositories.dll is instantiated on runtime per IOC-Container.
When we build the solution in VS2010 and browse the web app everything is working fine, as expected.
When we use our build server(TFS 2010) und use the web deployment, the Repositories.dll is missing the web-app\bin folder and we got a runtime exception(when we want to instantiated a class in Repositories.dll)
But Repositories.dll is in our drop location, so the web deployment target does not copy this file, any ideas how to solve this??
Have you tried a copy task from the BuildTemp location to where your Web Deployment Project can pick up the file it needs?
<Copy SourceFiles="$(OutDir)\Repositories.dll" DestinationFiles="web-ap\bin\Repositories.dll" />
The paths will need modified but you get the idea. I do a similar function in MSBuild to move a dll for our installer to pickup.