Umbraco 9 instellisense does not work inside cshtml - umbraco

I have freshly installed vs 2022 and created Umbraco 9.5.1 project. When I go to generated view, for example Views/test.cshtml and try to see the members of Model, I get nothing:
I tried setting the following option:
"Umbraco": {
"CMS": {
"ModelsBuilder": {
"ModelsMode": "SourceCodeManual",
"ModelsDirectory": "~/umbraco/models"
},
But it started giving me the following error:
How can I enable intellisense in the views?

Make sure to include all the generated files in you project/solution, as well as the view files. That should do it?

Related

Calling Another Project's Controller From A Project In The Same Solution (.NET Core )

There are 2 projects in the same solution. First project is a .NET Core project and it has all the codes(controllers, models etc.) related to packages. I need to get the information (id, name, description) of the packages and display it in the second project(.NET Core Web App with Razor). Is it possible to do it without changing the first project? I only want to show the package list on a single web page.
I tried calling the first project's controller but it didn't work. Maybe I missed a point. Any help is appreciated.
This requirement can be achieved, please see the gif image below.
Tips
If you want to call another project's controller from a project in the same solution, you need to make sure there is in HomeController in both project. I mean the name of any class should be unique in both projects.
Otherwise you will face the same issue like my homepage.
Test Code:
public List<PackageReference> GetPackageList5(string projectname)
{
List<PackageReference> list = new List<PackageReference>();
PackageReference p = null;
XDocument doc = XDocument.Load(_webHostEnvironment.ContentRootPath+ "/"+ projectname + ".csproj");
var packageReferences = doc.XPathSelectElements("//PackageReference")
.Select(pr => new PackageReference
{
Include = pr.Attribute("Include").Value,
Version = pr.Attribute("Version").Value
});
Console.WriteLine($"Project file contains {packageReferences.Count()} package references:");
foreach (var packageReference in packageReferences)
{
p = new PackageReference();
p.Version= packageReference.Version;
p.Include= packageReference.Include;
list.Add(packageReference);
//Console.WriteLine($"{packageReference.Include}, version {packageReference.Version}");
}
return list;
}
My Test Steps:
create two project, Net5MVC,Net6MVC
add project reference.
My .net6 project references a .net5 project. So in my HomeController (.net), I add below:
using Net5MVC.ForCore6;
using Net5MVC.Models;
Suggestion
When we reference the .net5 project in .net6 project, we can build success, but when we deploy it, it always failed. The reason is some file was multiple publish output files with the same relative path.
Found multiple publish output files with the same relative path:
D:\..\Net6\Net6\Net5MVC\appsettings.Development.json,
D:\..\Net6\Net6\Net6MVC\appsettings.Development.json,
D:\..\Net6\Net6\Net5MVC\appsettings.json,
D:\..\Net6\Net6\Net6MVC\appsettings.json.
And usually will add class library to current project, not add a web project.
As we know we can find packages info in .csproj file, so we need copy and paste .csproj file to publish folder.
I still recommend using the GetPackageList5 method above as an interface for your project, using HttpClient for requests.

URL in CSS no longer works in Vaadin 14.6

After upgrading from Vaadin 14.5 to 14.6 I'm facing problems with CSS that contains URL's that point to content.
For example, the following CSS no longer works:
:host([part="my-part"]) [part="reveal-button"]::before {
content: url("../images/my-image.svg");
}
It fails to "compile" when running the build-frontend goal of the Vaadin Maven plugin with the following error:
ERROR in ../node_modules/#vaadin/flow-frontend/styles/components/my-component.css
Module build failed (from ../node_modules/css-loader/dist/cjs.js):
Error: Can't resolve '../images/my-image.svg' in '<Project Path>\node_modules\#vaadin\flow-frontend\styles\components'
The same error appears in the browser if I try to run the project. This CSS has worked fine in all previous versions of Vaadin 14.
Has anyone encountered anything similar, or have any ideas as to what has changed that might cause this?
With the new custom theme feature the .css loader has changed from raw-loader to css-loader but it shouldn't touch urls outside of frontend/themes/[theme-name] or node_modules
Is the styles/components/my-component.css located in src/main/resources/META-INF/frontend, src/main/resources/META-INF/resources/frontend or src/main/resources/META-INF/resources to be packaged as an add-on jar or compatibility mode?
As in that case the css would end up inside node_modules which might make a difference to the resolving.
As a workaround if you are not building an add-on you should be able to move the css and image to {project_root}/frontend and it should build fine.
Until release of 14.6.2 you can add the raw-loader dependency to a java class with
#NpmPackage(value = "raw-loader", version = "3.1.0")
and then add to webpack.config.js the lines
if(flowDefaults.module.rules[2].test.toString().includes('.css')) {
flowDefaults.module.rules[2].use = [ {loader: 'raw-loader' }];
} else if(flowDefaults.module.rules[1].test.toString().includes('.css')) {
flowDefaults.module.rules[1].use = [ {loader: 'raw-loader' }];
}
Did you change the css structure to follow the new theme structure introduced in 14.6? It is not needed, but it is important context. I think it is at least related to your issue.
The path seems a little weird in your error messages, ending up in a node_modules folder. Could you share where this file is in, and what loads the file to your project?
With the new theme structure, I've used the following css to import images in css:
background: url('./images/fire.png');
And that was placed in a file: frontend/themes/mythemename/mythemefile.css

Angular 4+ 3rd party module import 404 error with base tag

I am putting an angular portion into my MVC app. As such, I have added a tag to my layout view to find the Angular source code, and this is working great.
My issue arises in trying to add a 3rd party module to my project. I added it through the package.json with no problem, and added the module to my app.module.ts as follows:
import { FileUploadModule } from 'primeng/fileupload';
The reference is found, Visual Studio is happy, everything is fine. However, when I run the project locally, I get the following 404 error:
GET http://localhost:59911/src/primeng/fileupload 404 (Not Found)
It seems to me likely that the tag is causing the issue, but I can't remove it without killing the rest of the Angular functionality. Any hints? Can I add an override to the imports call?
Thanks, Mike
On PrimeNG's official website they suggested using import { FileUploadModule } from 'primeng/fileupload'; but it doesn't work any more. I guess they didn't update the docs.
You need { FileUploadModule } from 'primeng/primeng';
The structure is
In the primeng.d.ts file PrimeNG re-exported all modules.
export * from './components/fileupload/fileupload';
For now, no matter which PrimeNG module is used, it is all from primeng/primeng. Here's the imported modules in my project:
import {
ButtonModule,
CodeHighlighterModule,
ConfirmDialogModule,
FieldsetModule,
FileUploadModule,
GrowlModule,
MessagesModule
} from 'primeng/primeng';
The version I use is "primeng": "^4.2.1"
The issue was that primeng was not in the mapping, so it was looking for it in src.
I added the following to systemjs.config.js:
in maps:
'primeng': 'npm:primeng',
in packages:
primeng: {
defaultExtension: 'js'
}
Thanks for the help everyone!

Grails render view from different plugin when deployed

I have a problem, which only is an issue when my application is deployed - there is no issue when developing.
I have 2 controlleres. One controller residing i a plugin which the second is extending. There exists a specific template in a view folder - /templates/_mytemplate.gsp in the "main" project -that is, not in the plugin.
The "common-controller" has a method for rendering various templates based on a string. And this is where the trouble starts. Using:
String summary = groovyPageRenderer.render(template: "/mycontroller/templates/_mytemplates.gsp", model: [foo: bar])
Works perfectly fine in development but when war-deployed, the string is empty. I have narrowed the problem down to be of resolveSearchPaths method in DefaultGroovyPageLocator [1] which differentiates the lookup path.
Anyone? What would be reasonable solution? Preferable the templates are not located in the plugin....
I ran into a similar issue with a release a few days back and used something like:
try {
//look for template in the main app
def html = render(template:'/mycontroller/templates/mytemplates', model: [foo: bar])
if(html && html.size() > 0) {
render html
}
} catch (Exception e) {
//bad way to handle template not found.
}
//fallback on the template defined in the plugin
render(plugin:'myPlugin', template:'/mycontroller/templates/mytemplates', model: [foo: bar])
This probably isn't the best way to handle this issue but at least gets the deployed war working.
Stupid stupid stupid!
Developing on windows - deploying to Unix. So forgot a camelcase T <- which works on Windows not on Unix :)
So to make it work:
String summary = groovyPageRenderer.render(template: "/mycontroller/templates/_my**T**emplates.gsp", model: [foo: bar])

Intellij IDEA-Grails GDSL Not Working

I tried to use GDSL Scripts for my grails project in IDEA.
I tried things as shown in the Guide: GDSL Guide. The Steps I followed were:
Created a myDef.gdsl file in my project home(i.e. in the folder
that containg grails-app, web-app etc)
In that file i added this code:
def ctx2 = context(ctype: "com.myPackage.MyClass")
contributor(ctx2) {
method(name: 'withLock', type: 'void', params: [closure: { }])
}
Clicked on Activate.
But it still does not show any autocomplete or recognise when I do:
Myclass m = new MyClass()
m.withLock() //This is not recognised
What am I doing wrong??? :(
Details:
Idea Series: Ultimate
Idea Version: 107.535
The GDSL file should be located under some source root. Grails module content roots aren't source roots. So please consider putting it into src/main/groovy, for example.

Resources