Hey this is a part of my project.json file:
"scripts": {
"prepublish": [
"node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js",
"node node_modules/webpack/bin/webpack.js"
],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
},
I want to invoke prepublish scripts every time I publish the application even if it's a development environment and I am running it through visual studio or dotnet run. Prepublish doesn't seem to work in these cases
When you run through VS or using 'dotnet run', you only build and run the application from source, without publishing. Publishing scripts will be triggered, if you call dotnet publish.
The dotnet run command provides a convenient option to run your application from the source code with one command. It compiles source code, generates an output program and then runs that program.
Right now only the following types of script are supported:
precompile
postcompile
prepublish
postpublish
and what you want is more like "beforerun"/"postrun". As a workaround you may try to call your scripts directly from code in your application entry point.
Related
I am trying to debug a simple "Hello world" application in VS Code, however, when I press Ctrl + F5, it gives me the following error:
If I manually change the path in launch.json from:
${workspaceFolder}/bin/Debug/insert-target-framework-here/insert-project-name-here.dll
To:
"${workspaceFolder}/bin/Debug/netcoreapp2.1/test.dll"
It does work, however before it was working fine without me manually typing the path. Also, I have noticed that VS Code no longer asks to rebuild assets like it did before:
So far I have tried the following:
Uninstalled VS Code, then .NET Core 2.1, deleted the VS Code extension folder from %USER%\.vscode\ , re-installed VS Code, then .NET Core 2.1, and then the C# extension (C# for Visual Studio Code (powered by OmniSharp)).
When the VS Code starts, it does download the "OmniSharp" package successfully, but still, no prompt to rebuild assets when I open a C# file. Debugging gives the same issue as before.
Here is the launch.json:
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
}
And the tasks.json:
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet build",
"type": "shell",
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
I found a solution that worked for me.
My VS Code was giving me the same error message, and what I did to fix it was:
- Press the combination Ctrl + Shift + P
- Restart Omnisharp
- Then it asks if you want to add missing files for build.
- Click Yes.
After this I was able to debug my app.
Hope it works for you!
Visit your \bin\Debug\netcoreapp3.1 in your project folder (That you open in VS)
Go to launch.json file in VS:
Replace:
"program": "${workspaceFolder}/bin/Debug//.dll",
With:
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/CSharp.dll",
In may case, the project is called CSharp. Watch out.
I had a the same error. The debugger was looking for the .dll file in ${workspaceFolder}/bin/Debug/netcoreapp3.1/myApp.dll but the file was located in ${workspaceFolder}/bin/MCD/Debug/netcoreapp3.1/tradeAppl.dll
After changing the launch.json file to read
...
"program": "${workspaceFolder}/bin/MCD/Debug/netcoreapp3.1/tradeAppl.dll",
...
I was able to debug the application without any problems.
Since you have :".dll" taged with "<" and ">", it means that you have give it a value.
The easiest way to do it is to open the project in VSCode and use find&replace to replace the:
with your project name which I do believe its: "test" as per the .dll name
Configure your Launch.json like this Gist
And there is no need to Tasks.json , you can Press F5 to build or configure it your self to which command should be run in default shell when you press F5
// "program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/csharp_multi_threads.dll",
You need to change the program value as it reminded
I switched to MS Visual Studio, since I did not find any other solutions.
-Right Click on Project Name And Click on Reveal in Explorer
-Copy Url In Explorer After Folder Name
For Example My Folder Address is
D:\IOT\Projects\LWSIOT_WebApiWM2\LWSIOT_WebApiWM2\LWSIOT_WebApiWM2\bin\Debug\netcoreapp3.1\LWSIOT_WebApiWM2.dll
And In Launch.json :
${workspaceFolder}/LWSIOT_WebApiWM2/LWSIOT_WebApiWM2/bin/Debug/netcoreapp3.1/LWSIOT_WebApiWM2.dll
-Paste in Launch.json on "Program":"<Your_Address>"
-Click On Debug And Its OK
In launch.json , replace :
"program": "${workspaceFolder}/Api/bin/Debug/netcoreapp3.1/Api.dll",
with:
"program": "${workspaceFolder}/Api/bin/linux/Debug/netcoreapp3.1/Api.dll"
Since I was running code in Linux machine so I should have provided Linux Folder' path
Must be an issue with the path to the dll in the program property of the launch.json file.
In my case, it still contained the old .net core framework version after the version upgrade.
I recently upgraded my version of VisualStudio Code to the latest release and am I getting an error when trying to debug csharp applications. I am running in windows 10 (14393) and am using vs code 1.23.1. I have an application that I created a few months ago using visual studio code and at the time it was working fine. it is a MVC application that uses dotnetcore2.0. When I try to run debugging I get a message "command 'csharp.coreclrAdapterExecutableCommand' not found. I can execute the application by running "dotnet run" from the project folder.
I tried creating a new blank console application that just says "hello world" and again am able to run from "dotnet run" but when I try to debug I get the same message. I am able to run the build task successfully.
I tried to reseaerch the method mentioned in the error but can find little to nothing about it. I believe that omnisharp is the solution that the csharp debug runs in and I looked it up. From their documentation it says that it needs .net framework 4.6 to work. I verified that I have the sdk and runtime for each .net framework installed.
I am usually pretty good at figuring things like this out and this is my very first post on stack. I am hoping that someone might know what the heck this is so that I can move forward.
It would be good to note that I have tried to reboot my machine several times and even uninstalled/reinstalled vs code. An example of the launch.json file is below.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/helloworld/bin/Debug/netcoreapp2.0/helloworld.dll",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
Thanks to #bman7716 I was able to figure out what was going on. The issue was the omnisharp extension was corrupted (or a related dependency). I was able to resolve the issue by:
Uninstalling the c# extension from VS Code
Close VS Code
remove all C:\Users{username}.vscode\extensions\ms-vscode.csharp-{version}
Open VS Code
Install C# extension
Open Project
Go to Debug mode and start debug
This forced VS Code to re-install omnisharp and its dependencies and things worked just fine afterwards.
Every time I build a project using the new .NET Core RC2 templates I am not provided with a runnable .EXE file. If I hit F5 for debugging my console application it runs fine through the
C:\Program Files\dotnet\dotnet.exe
application. And if I use the
dotnet run
command in the folder, it runs fine as well. But I see no way to run the application without the .NET Core CLI tools.
The contents of my
bin\Debug\netcoreapp1.0\
folder looks like this:
As you can see there is no .EXE file available. Just the dll.
Am I overlooking something? Or is there something wrong with my project.json file?
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002702"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
Thanks!
There are actually 2 app models in .NET Core:
Portable apps: heavily inspired by "DNX console apps", these apps don't produce .exe files and are instead executed by the .NET Core shared runtime (whose version is defined by the Microsoft.NETCore.App package, thanks to its special type: platform attribute). The corresponding .NET Core runtime must be installed on the machine to be able to use portable apps. If the exact version cannot be found, an exception is thrown when running dotnet run.
Standalone apps: standalone apps are really similar to good old .NET console apps as they produce .exe files. The .NET Core runtime doesn't have to be installed on the machine, because it is directly embedded with the application itself.
You're currently using the first model. To use the standalone model, you need to tweak your project.json:
Add a runtimes section to list the environments your app will target (e.g win7-x64 or ubuntu.14.04-x64). You can find the complete list here.
Remove the Microsoft.NETCore.App dependency. You can replace it by this package instead: "NETStandard.Library": "1.5.0-rc2-24027".
Here's an example of a standalone app:
{
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"warningsAsErrors": true
},
"dependencies": {
"Microsoft.Extensions.Configuration.Binder": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
"NETStandard.Library": "1.5.0-rc2-24027"
},
"frameworks": {
"net451": { },
"netcoreapp1.0": {
"dependencies": {
"System.Net.Ping": "4.0.0-rc2-24027"
},
"imports": [
"dnxcore50",
"dotnet5.6",
"portable-net451+win8"
]
}
},
"runtimes": {
"win7-x64": { }
}
}
The answer is in the documentation with complete steps now.
You can create two types of deployments for .NET Core applications:
Framework-dependent deployment
Self-contained deployment
For a runnable .EXE file, the Publish self-contained should be used.
To create a runnable application from a .NET Core console application you can use the dotnet tool. Just run in your project directory:
dotnet publish --runtime win7-x64
This creates a standalone app (self-contained deployment; includes all necessary libraries consuming at least 60MB on your disk). Of course you can also choose other runtimes, like osx.10.11-x64 or ubuntu.16.04-x64.
If you used the default configuration (New Project -> Console App (.NET Core)), there is no modification of any configuration file necessary.
step 1: remove "type": "platform", from Project.json under frameworks section
step 2: add run time section to your project.json. Note each section is separeted by a comma. Add your runtime. below is just an example for win 10.
"runtimes": {
"win10-x64": {}
}
Step 3: dotnet restore command on your project. ( open cmd, go to your project folder wherever src folder is there, run dotnet restor)
step 4: dotnet pack
step 4: dotnet build -r win10-x64 - or just build.
Step 5: you can notice .exe created under debug/netcore/win10/
In ASP.NET Core try changing your app type to default, in project.json:
"Microsoft.NETCore.App": {
"type": "default",
"version": "1.0.0-*"
}
I have a 'Hello World' Kestrel server generated by Yeoman (as described here).
yo aspnet
When I run the site via the command line everything work well:
dotnet run
If it's run through Visual Studio Code though bootstrap.css, jquery.js and bootstrap.js don't load (404).
Looking at the F12 tools, they are actually coming from different locations. When run via dotnet run they come from https://ajax.aspnetcdn.com/..., but when run through Visual Studio Code the browser is looking for them in a local folder ~/lib/....
a. Why are the files being sourced differently depending on how I run the site?
b. How do I fix this?
Thanks
When you run it from command line, it runs in production mode (no ASPNETCORE_ENVIRONMENT variable set. When you run it from Visual Studio it sets the ASPNETCORE_ENVIRONMENT to Development.
Inside your Razor files, you have a <environments> section which controls which files are served in which production mode. Depending on your environment/OS, you need to set the variable differently. i.e. in Linux you'd need to run ASPNETCORE_ENVIRONMENT=Development dotnet run.
As for the reason why you get 404 when running in development mode, you probably need to copy over the wwwroot folder to your output directory, with this entry in your project.json.
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"copyToOutput":
[
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
Though usually it should be necessary to add wwwroot to copyToOutput
I feel like I'm missing something obvious, but searching google, this site and the .Net Core SLI issues section on GitHub did not immediately return an answer, nor did reading the documentation for the .Net Core project.json format.
In plain old C# projects (regular .Net, not Core) scaffolded by Visual Studio (not VSCode), usually running a build will put files in
%project root%/bin/Debug
out of the box, or
%project root%/bin/Release
if you choose publish.
In VSCode with .Net Core, by default build puts files in
%project root%/bin/Debug/netcoreapp1.0.
however if you run
dotnet publish
on the command line, it will put the files in a release folder inside
%project root%/bin/Debug/netcoreapp1.0.
resulting in a structure like
%project root%/bin/Debug/netcoreapp1.0/release.
If you have specified to build for a specific platform target in your project.json then it will similarly put the files in
%project root%/bin/Debug/netcoreapp1.0/PlatformName.
For example
%project root%/bin/Debug/netcoreapp1.0/win7-x64.
My question is, why does .Net Core put the release folder inside the debug folder and since I prefer the old directory structure, is there a way I can tell .Net Core to do it that way instead, say via some project.json property or cli flag similar to how say typescript allows you to specify an outDir?
Testing this with the default hello world project provided by 'dotnet new', my modified project.json looks like this:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
//"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
},
"runtimes": {
"win7-x64": { }
}
}
According to the documentation (bold is mine):
dotnet publish [--framework] [--runtime] [--build-base-path] [--output] [--version-suffix] [--configuration] []
...
-c, --configuration [Debug|Release]
Configuration to use when publishing. The default value is Debug.
So you need to use:
dotnet publish -c Release
(there's also the --output parameter to specify the destination folder: the documentation also states the default, which matches what you are seeing)