This is the content of my tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"/Crm/AdminApi/Api.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": ""
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"/Crm/AdminApi/Api.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": ""
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"/Crm/AdminApi/Api.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": ""
}
]
}
The problem is that when I run it using F5 it fails because it runs as the vscode user I guess.
Also when I run dotnet build from inside the VS Code terminal, it does not work.
However, when I run sudo dotnet build in the VS Code terminal, or when I run dotnet build from a root bash terminal, it works.
How can I force VS Code to run my code as the root user? I tried "command": "sudo dotnet" but it did not work.
Related
I am trying to write log into "LocalApplicationData" using Serilog and using below configuration, but it's not working. If I try to write in some hard code path like "path": "C:/Temp/Logs/log.txt" then this is working. How to write into local app data folder?
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "${specialfolder:folder=LocalApplicationData}/Logs/log.txt",
"fileSizeLimitBytes": "5242880",
"rollingInterval": "Day",
"retainedFileCountLimit": "15",
This format is used in NLog. The equivalent is to use %LOCALAPPDATA% instead:
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "%LOCALAPPDATA%/Logs/log.txt",
"fileSizeLimitBytes": "5242880",
"rollingInterval": "Day",
"retainedFileCountLimit": "15",
Please note that this will only work in appSettings.json. To do the equivalent in C# you can use Environment.GetEnvironmentVariable("LocalAppData")
I am trying to post a Messageback Adaptive card but I am below getting error in emulator:
The card could not be rendered. It is either malformed or uses features not supported by this host.
I am using AdaptiveCards 1.2.2 version. I am using C# to post this adaptive card but I am not able to figure out the issue.
My Json File:
{
"type": "AdaptiveCard",
"selectAction": {
"type": "Action.Submit"
},
"body": [
{
"type": "TextBlock",
"text": "1:1 with John Doe",
"weight": "Bolder"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "Image",
"url": "https://images.idgesg.net/images/article/2019/04/google-calendar-android-100794956-large.jpg",
"altText": "Calendar",
"size": "small"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "Tomorrow, 30 May"
}
],
"width": "stretch"
}
]
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "Image",
"url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg",
"altText": "Calendar",
"height": "20px"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "John Doe",
"spacing": "Medium"
}
],
"width": "stretch"
}
]
},
{
"type": "TextBlock",
"text": "Slots available - **1 hr duration**",
"separator": true,
"spacing": "Medium",
"isSubtle": true
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"actions": [
{
"type": "Action.Submit",
"title": "11:00 AM",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "11:00 AM",
"text": "text to bots",
"value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
}
}
}
]
}
],
"width": "auto"
},
{
"actions": [
{
"type": "Action.Submit",
"title": "Cancel",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "Cancel",
"text": "text to bots",
"value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
}
}
},
{
"type": "Action.Submit",
"title": "Confirm",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "Confirm",
"text": "text to bots",
"value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
}
}
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
A great way to test your Adaptive Cards is to use the Adaptive Card Designer or the card editor in App Studio in Microsoft Teams. If a preview isn't rendered then there's something wrong with your card.
In your case, you say you want to use Adaptive Cards 1.2.2 but you're including "version": "1.0" in your JSON. You might want to say "version": "1.2" instead, but keep in mind that the higher the version of your Adaptive Card the fewer clients will be able to render it.
More importantly, you're putting an actions property in both columns and column sets and neither of those have an actions property. Please refer to the schema to see what elements have what properties. You might mean to use an action set (a 1.2 feature), or you might just want to use the actions property of the card itself outside of the card's body.
More importantly still, you have more opening brackets than closing brackets and so your JSON is invalid. I suspect you forgot to close your last column set and its columns array. Please use an editor like Visual Studio Code to automatically format your JSON and make sure it's valid. It's also good etiquette to correctly format your JSON in your Stack Overflow question so that other people can read it without formatting it for you.
Please read my latest blog post for more information about Adaptive Cards and using them with the Microsoft Bot Framework.
I'm using Serilog on a .net core.
I want to config the log path to the application directory.
I see there's an extension https://github.com/serilog/serilog-settings-configuration that enable Serilog to read from Configuration.
In the example , the path is configured as "%TEMP%\\Logs\\serilog-configuration-sample.txt".
How can I set it to the working directory?
I've searched on so, and know that it can be done by code, but it seems there's no one asking how to do this by the config file, i.e. appsettings.json.
Current configuration:
{
"Serilog": {
"Using": [
"Serilog.Sinks.File"
],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "File",
"Args": { "path": "Logs\\serilog-configuration-sample.txt" }
}
],
"Enrich": [ "FromLogContext", "WithMachineName" ],
"Destructure": [
],
"Properties": {
}
},
"AllowedHosts": "*"
}
I want the log path to be set to the working directory.
But currently it's in "C:\Program Files\IIS Express".
Configuring path like Logs/log.txt will write log files under logs folder in working directory
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/log.txt"
}
}
Also you can check this answer for another option
You can add a "RollingFile" wich can write to a local path file. In this example I'm writing in a File inside of the root of my project as it shows bellow.
{
"Name": "RollingFile",
"Args": {
"pathFormat": ".\\Logs\\logs.txt",
"fileSizeLimitBytes": 1048576
}
},
Also the full json on appsettings.json end up like this (in case you need a full example)
...
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"System": "Debug",
"Microsoft": "Debug"
}
},
"WriteTo": [
{
"Name": "ApplicationInsightsEvents",
"Args": {
"instrumentationKey": "xxxxxxxxxx"
}
},
{
"Name": "RollingFile",
"Args": {
"pathFormat": ".\\Logs\\logs.txt",
"fileSizeLimitBytes": 1048576
}
},
{ "Name": "Console" },
{
"Name": "EventLog",
"Args": {
"source": "API NAME",
"logName": "CustomLog",
"restrictedToMinimumLevel": "Warning"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Properties": {
"Application": "API NAME"
}
}
...
In the kestrel part of my BuildWebHost, I can verify that the url is set to https://localhost/5000. However, when host.run() is called, only https://localhost is launched for some reason.
`
.UseKestrel(options =>
{
X509Certificate2 certificate = null;
if (!string.IsNullOrEmpty(certFileName) && !string.IsNullOrEmpty(certPassword))
{
certificate = new X509Certificate2(certFileName, certPassword);
url = "https://localhost:5000";
}
options.Listen(IPAddress.Loopback, 5000, listenOptions =>
{
if (certificate != null)
{
listenOptions.UseHttps(certificate);
}
});
})
`
Additional Information:
It's launched when I run Visual Studio Code. My configurations files all say localhost:5000 This used to work. I changed my program property in launch.json to point at net2.0 path and that's when it stopped.
launch.json contents:
`
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
// "program": "${workspaceFolder}/bin/Debug/netcoreapp1.1/TennisFolderAPI.dll",
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/TennisFolderAPI.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
},
"requireExactSource": false,
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
`
For Visual Studio in launchSettings.json use "launchUrl": "http://localhost:5000".
Launch.json is for Visual Studio Code.
https://www.google.com/amp/s/andrewlock.net/how-to-set-the-hosting-environment-in-asp-net-core/amp/
When I click 'Start Debugging' in visual code I receive this error. No google results have worked so how do I fix it? I'm trying to compile C# code.
The preLaunchTask 'build' terminated with exit code 1.
I have added some code below of my launch.json file and the other file for my VS code as I wasn't sure if it would help being able to see them.
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"console": "internalConsole"
},
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceRoot}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [ ],
"isBuildCommand": true,
"showOutput": "silent",
"problemMatcher": "$msCompile"
}
]
}
There's a preLaunchTask configured in your launch.json file. It is the task that gets run before the script is executed. That task is 'build', from your tasks.json file. It is failing, as indicated by its return of a non-zero error code. You need to open up your tasks.json configuration file, see what the 'build' task entails, and then figure out why it is failing.