dotnet bundle not working in .net core mvc application - asp.net-core

I try to use bundleconfig.json, which is standard added to the project when I started the project. I read every where they say you have to run
dotnet bundle
But this is not working for me I get the error
No executable found matching command "dotnet-bundle"
Now I Googled and found that I have to add this in Project.json
"tools": {
"BundlerMinifier.Core": "2.2.281",
But I have no Project.json file only csproj. I thought I have to install package. So I installed BundlerMinifier.Core but still same error.
What do I have to do so I can run the code and bundle my files?

According to https://learn.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification?view=aspnetcore-2.1&tabs=netcore-cli%2Caspnetcore2x you have to install the CLI tools for dotnet to do this.
From a command line in the project directory it looks like you do this:
dotnet add package BuildBundlerMinifier
dotnet build
and you should get this result
Microsoft (R) Build Engine version 15.4.8.50001 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Bundler: Begin processing bundleconfig.json
Bundler: Done processing bundleconfig.json
BuildBundlerMinifierApp -> C:\BuildBundlerMinifierApp\bin\Debug\netcoreapp2.0\BuildBundlerMinifierApp.dll
The linked page also talks about ad-hoc bundling. Its on the microsoft site so it shouldn't go anywhere.

Related

How to find and use downloaded packages from nuget in vs2017 software (and in an asp.net core project)?

In Visual Studio 2017, I use the following command to install a package like .jQuery.Unobtrusive.Validation:
Install-Package Microsoft.jQuery.Unobtrusive.Validation -Version 3.2.11
And the operation is done successfully.
Now I'm looking for files on wwwroot but can not find anything? what is the problem?
Use LibMan :
In Solution Explorer, right-click the project folder in which the files should be added. Choose Add > Client-Side Library.
Type jquery-validation-unobtrusive#3.2.11 in Library input area .
Click Install , the library will install to target location . The default is wwwroot/lib/jquery-validation-unobtrusive/

npm cannot find SDK version from global.json

I'm in the thick of trying to get up-to-speed on asp.net core / npm / react using this as a base project template:
https://github.com/jonmcquade/aspnetcore-react-redux#local-no-docker
I originally ran into troubles once trying this command:
dotnet build -c Release -o ./app
The error I was seeing:
A compatible SDK version for global.json version: [2.1.0] from
[global.json] was not found Did you mean to run dotnet SDK commands?
Please install dotnet SDK from:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
I had the specific versions in the documentation installed and I have installed the latest versions, both x64 and x86 platforms.
I now also get this error running the npm install command or the dotnet --version command, yet I have SDKs installed.
It feels like the machine configuration has become broken somehow. I seem to have gotten into a bit of a version pickle trying to get the dotnet build command working and now even NPM isn't working.
Global.json is:
{
"sdk": { "version": "2.1.0" }
}
And the .csproj file contains:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.0-preview1-26216-03</RuntimeFrameworkVersion>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable>
<AssemblyName>FlightSearch</AssemblyName>
<RootNamespace>FlightSearch</RootNamespace>
<ApplicationIcon>ClientApp\favicon.ico</ApplicationIcon>
<Authors>Jon McQuade</Authors>
<Company>ACME Freelancing, Inc.</Company>
<StartupObject></StartupObject>
<Product>Flight Search</Product>
<Description>ASP .NET Core 2.1 MVC SPA with React and Redux</Description>
<RepositoryUrl>http://github.com/jonmcquade/aspnetcore-react-redux</RepositoryUrl>
<PreserveCompilationContext>true</PreserveCompilationContext>
<TypeScriptToolsVersion>2.8</TypeScriptToolsVersion>
<OutputType>Exe</OutputType>
<Version>2.1</Version>
</PropertyGroup>
What am I missing to get this working?
Are there some machine configuration issues that I can check? Maybe environment variables? I've tried running a repair using the installers but this doesn't address the issue.
The global.json specifies the SDK version of .NET Core that is being used to build your application. This has little to do with the .NET Core Runtime version that you want to run your application with.
Your application is a netcoreapp2.1, so you are running the .NET Core 2.1 Runtime. The earliest SDK Version for that is 2.1.300.
Since that is the latest .NET Core version, you actually don’t need to use a global.json at all: Just delete the file from your project and the tooling should use the latest version which is 2.1.300-rc1 on your machine.
If you're running into this issue on OSX you can fix the issue thusly:
which dotnet
ls + the output from the previous command
You should now see something like:
/usr/local/share/dotnet/dotnet
The directory that has your dotnet binary should also have a directory called sdk, so for the above example you can run ls /usr/local/share/dotnet/sdk, which should output a directory with your current version number. In my case that is 2.1.403 (there may be a better way to get the version number, but I was unable to run dotnet --version without specifying the correct sdk)
If I now open the global.json file in my app's root directory and change the sdk version to "2.1.403-osx-gs-x64", I should now be able to run dotnet command such as dotnet run from within my project.
Just make sure the required SDK version is installed in your machine. On your error, it's .NET core 2.1.0. You don't need the global.json file anymore.

Build mixed projects on Linux using MSBuild 15 fails

Can anybody assist me with the following issue I am having? I am trying to build a mixed solution on linux using MSBuild 15. It contains projects that targets netstandard2.0 and then also projects that target .Net 4.6.2
The netstandard2.0 projects build fine, but the projects that target .Net 4.6.2 fails with the following error:
Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore
I am using MSBuild version 15.6.0.0 for Mono and running on Ubuntu 17.10
quick fix: delete the obj/ directory and then rebuild.
The best I've got at the moment is
rm -rf obj ; msbuild /t:restore /t:build

Building .NET Core 1.0 RC2 app on the build server

I've updated my app from DNX, ASP.NET 5 RC1 to ASP.NET Core 1.0 RC2.
Locally it builds and runs fine.
On the build server, I don't have Visual Studio installed, and the build fails with:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
I did install the: .NET Core SDK for Windows.
Trying to install the VS 2015 tooling preview fails with:
What would be the correct setup to build .NET Core 1.0 RC2 app on the build server without having to install Visual Studio 2015?
Note: The build box (TeamCity 9) builds/runs tests fine for .NET 4.5 and DNX.
https://learn.microsoft.com/en-us/dotnet/articles/core/windows-prerequisites#issues
Issues
You may be blocked from installing the .NET Core Tooling Preview 2 for Visual Studio 2015 installer due to a temporary bug. To workaround it, run the installer from the commandline with the SKIP_VSU_CHECK=1 argument, as you see in the example below.
DotNetCore.1.0.0-VS2015Tools.Preview2.exe SKIP_VSU_CHECK=1
I'm able to build the solution now. Still can't publish though.
I just copied all the new MSBuild stuff to the build server. I copied:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\
From my local computer to the build server. That includes the new DotNet sub-folder, which contains:
Microsoft.DotNet.Common.targets
Microsoft.DotNet.Extensions.targets
Microsoft.DotNet.props
Microsoft.DotNet.Publishing.targets
Microsoft.DotNet.targets
Microsoft.DotNet.Tasks.dll
Microsoft.VisualStudio.ProjectSystem.DotNet.Runtime.dll
Newtonsoft.Json.dll
I can build the Solution (without the publish arguments) it fails when I try:
MSBuild.exe Solution.sln /p:DeployOnBuild=true /p:publishprofile=local
You can build and test you project via the command line - so there is no need to have Visual Studio installed. By using build steps of type "Command Line" you can run: dotnet restore, dotnet build, dotnet test
Here you can find some description how to run that as a build on TFS. It is written for the hosted TFS but works on-premise as well (and is not only meant for azure as the name of the document might imply):
https://www.visualstudio.com/en-us/docs/build/apps/aspnet/aspnetcore-to-azure
For the pubsishing I have used msdeploy with RC1 but have not yet migrated my deployment build. I might document it here when this is done within the next days.
So without Visual Studio or Web Deploy, my TeamCity build is comprised of 4 builds steps:
dotnet restore
dotnet build
dotnet test
dotnet publish -c Release
I run dotnet test on all projects with a basic for loop.

How to make aspnet_compiler compile project dependencies?

I try to compile my web project with aspnet_compiler.
aspnet_compiler -f -fixednames -u -v / -p C:\test\testproj\testproj c:\test\output -c
The testproj is a web site that has a dependency to a class library called MyLib.
The problem is that aspnet_compiler only compiles the web site and not the class library MyLib.
So whenever I make changes to the class library I have to either manually build the MyLib using msbuild and copy the .dll. Or rebuild the solution in visual studio.
How can I make aspnet_compiler rebuild all referenced projects?
Unfortunately the aspnet_compiler cannot build any of the project dependencies of your web site. To do this, there are a couple of options available to you:
If you are using Visual Studio 2005 or 2008, create a Web Deployment project (first you'll need to download and install these from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=0AA30AE8-C73B-4BDD-BB1B-FE697256C459) and then use MSBUILD.EXE to compile your web site and all of its dependencies:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBUILD C:\test\testproj\testproj.wdproj /target:Clean;Rebuild
If you are using Visual Studio 2010, you can migrate your web site to an ASP.NET Web Application project which uses a .csproj file that can be compiled with MSBUILD (no additional downloads required):
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBUILD C:\test\testproj\testproj.csproj /target:Rebuild;Package