How to automatically compile less files in an asp.net core project - .net-core

I have an asp.net core project.
This project contains less style sheet files.
I can see a compilerconfig.json and compilerconfig.json.defaults files at the root of the project.
This 2 files contains less compilation rules.
But when I type "dotnet build", the less files are not compiled in css.
Is there a specific command to type in addition of "dotnet build" ?
Thanks

You can right click compilerconfig.json and enable it. Also it has Ci support.
Nuget Package: source
<PackageReference Include="BuildWebCompiler2022" Version="1.14.8" />
cmd:

Related

Bower ASP.NET Core MVC missing jquery.validate.js file

UPDATE:
Visual Studio - File - New - Project
- ASP.NET Core Web Application (.NET Core) - Web Application
I left the default name WebApplication1
expand the wwwroot folder
expand up to wwwroot/lib/jquery-validation
in the jquery-validation folder we can see this (see img below)
- right click the WebApplication1 project in the src folder
- click on Manage Bower Packages
- Bower Package Manager screen asking to update jquery and jquery-validation (see img below)
clicked Update jquery
**everything looks normal (see img below)
clicked Update jquery-validation
dist folder has disappeared (see img below)
The text below is before I UPDATED this Q
I created an empty ASP.NET Core MVC web application in VS2015CE.
I added the bower.json file, that manages client-side stuff of the app.
Via Bower I downloaded jquery, jquery-validate, jquery-validate-unobtrusive.
Bower created a lib folder in the wwwroot folder.
Somewhere in the ~/lib/jquery-validate/ I should be able to find jquery.validate.js and it's "child" - the jquery.validate.min.js
There were no such files there, so I became suspicious and I created another project, this time a NOT empty web application.
I then compared both jquery-validate folders in the lib folders of the two applications.
My first project (created as EMPTY) has the following folder
structure:
dist folder is not present
My second project (created as WebApplication, NOT empty) has the
following folder structure:
dist folder is present and inside it there's the jquery.validate.js file and also it's child, the jquery.validate.min.js file.
What am I doing wrong? Or is it a bug in VS2015? Or a Bower bug?
You need to run the Grunt file which will build the dist folder for you. The best way I've found to do this right now is to install the Grunt Launcher extension. You can then right click on the package.json file within the jQuery-validation folder and select "NPM Install". That should build the dist folder for you.
I haven't found a way to automate this yet, but I'm sure there is. Just started using Gulp and wasn't using Grunt until I ran into the problem you're having. If someone has some tips there, that would be great. Good luck!
Right click on Bower.json file and select Open Command Line ==> PowerSell
type bower update
That's how I resolved my problem..
If Bower doesn't restore the correct packages:
delete everything from the directory value specified in .bowerrc which is located into your web project folder (e.g. wwwroot/lib)
open Git Bash (Git SCM for Windows -> when installing, choose Git Bash option)
go to your web project folder (where bower.json is located)
run the following:
bower cache clean
bower install
OR
bower update
Below it's an example of bower.json file:
{
"name": "asp.net",
"private": true,
"dependencies": {
"bootstrap": "3.3.7",
"jquery": "2.2.0",
"jquery-validation": "1.14.0",
"jquery-validation-unobtrusive": "3.2.6"
}
}
Unfortunately, none of the above offered solutions worked for me.
The problem was solved by smart people at Microsoft with a VS update or by those working on open source stuff.
Must have been a bug or something.
Anyway, thanks for the help guys..

Typescript compile on build not working

I have VS2015 and ASP.NET 5 RC1 project with some typescript files. Files are located in scripts folder and tsconfig is in this folder too. When I'm saving typescript file, js file is generated and everything is ok. But js files are not generated during build.
I have VS2013 installed also and some old projects using typescript, so may be there are some problems cause I have many TypeScript versions and many VS versions.
How can I troubleshoot compiling typescript during build? Build log says nothing about typescript. Checkbox 'Compile TypeScript on build' is project settings is enabled. In old ASP.NET projects TypeScript is enabled via custom target in csproj and it's easy to troubleshoot. But in xproj I don't see any typescript related things.
My current working solution is to add postbuild event which manually calls TypeScript compiler.
project.json:
"scripts": {
"postbuild": ["tsc -p scripts\\tsconfig.json"]
}
(assumes you have tsc in your PATH variable)
make sure this is added in your solution file
"Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"
I had the exact same issue. Worked for me when I edited tsconfig, and placed compileOnSave BEFORE compilerOptions in tsconfig:
{
"compileOnSave": true
"compilerOptions": {
....
},
}

How do you include build outputs as additional files using web deploy (MSDEPLOY)?

I have a web project that has a post-build event that produces some minified files. Assume for the moment that this needs to remain a post- build event, and cannot be changed into a pre-build event.
I have successfully used a .wpp.targets file to package additional files:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<SourceRoot>$(BuildDirectory)\Sources\Web</SourceRoot>
</PropertyGroup>
<ItemGroup>
<FilesForPackagingFromProject Include="$(SourceRoot)\ExtraScripts\Normal.js">
<DestinationRelativePath>Scripts\%(RecursiveDir)%(FileName)%(Extension)</DestinationRelativePath>
<FromTarget>Web.wpp.targets</FromTarget>
</FilesForPackagingFromProject>
</ItemGroup>
</Project>
Unfortunately, this fails when I do the same thing for the files produced by the post-build step. This is because the CopyAllFilesToSingleFolderForMsdeploy target executes before the build. Even before the PrepareForBuild target.
Is there a way to add extra files and folders to the deploy package when they are produced during the build?
There was a similar question before (Add Plugin DLL in MVC 4 Website after publish).
You can deploy files only if they have been a part of your project before.
What we usually do is that we include those files as dummy files in our project and overwrite them during the build process. Because those files are part of your project, this approach will publish those files.

How To Run MSBuild scripts in .wixproj?

Im trying to learn to make a web installer using Windows Installer XML (WIX 3.5). I found this blog about using msbuild in .wixproj files to avoid the scenario where the installer ends up dropping the web project assemblies right in the root of the app instead of keeping them in the bin folder like they're supposed to be.
Here is the link to that:
<http://www.paraesthesia.com/archive/2010/07/30/how-to-consume-msdeploy-staged-web-site-output-in-a.aspx>
But after adding the MSBuild scripts in the .wixproj file, I don't know what to do anymore. According to the instruction after adding the MSBuild script:
"When that target runs, you'll see a .wxs file pop out in the .wixproj project folder. Add the generated .wxs to your .wixproj project so it knows to include it in the build."
I really don7t know what this means. How can I run the target? I tried to build it but there was no .wxs file generated in the .wixproj folder.
Am I missing something? Please help...
Assuming you have added the section from the tutorial:
<Target Name="BeforeBuild">
...
</Target>
The target will be run automatically when you build the project. The "BeforeBuild" target is one of the standard entry-points to add your own modifications to the build. The target will then generate a file (named [WebProjectName].wxs that is placed in the same directory as your wixproj file. Click on the show all files button in visual studio and right-click on the file and "Include in project" That will then include the wxs is your installer and when you next build it will have the correct folder/file structure.

AspNetCompiler including files that are not in my project

I'm using msbuild to automatically build and package a website ready for deployment. When I compile and then Publish my project through Visual Studio 2008 everything works fine.
However when I use msbuild I'm getting errors because AspNetCompiler is trying to compile aspx and ascx files that are not included in my .csproj, but still exist in version control.
I know I can just remove them from version control, but can anyone tell me why these files are being compiled?
Here is my msbuild task.
<AspNetCompiler
TargetPath="$(PackageDir)\Web"
VirtualPath="/"
PhysicalPath="$(buildDirectory)\Web"
Force="true"
/>
Thanks!
The AspNetCompiler task, which wraps _aspnet_compiler.exe_, compiles all "compilable" files in the application, rather than compiling only those files in the .csproj.
The giveaway is that none of the command-line parameters for the executable take a .csproj as input, only paths. (I suppose one could argue that it would look for a .csproj in the directory, but that is unlikely as it would introduce its own set of issues, such as what to do if someone had put two project files in one directory.)

Resources