I created a .NET 6 console app with Visual Studio 2022 and set the command line arguments to:
Thisisa\newtest
When I launch the app, the \n in the string is replaced with a newline character. I don't recall ever observing this behavior before. I knew the command line can unescape sequences like \", but I've never heard of it happening for \n.
Why is newline character in an argument passed to Windows console application unescaped?
UPDATE:
Here is the code:
using System;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World! - " + args[0]);
}
}
}
Here is the debug profile:
{
"profiles": {
"ConsoleApp": {
"commandName": "Project",
"commandLineArgs": "Thisisa\\newtest"
}
}
}
I am using Visual Studio 2022, version 17.2.6. When the app is run the following is output:
this helped me:
args[0].Replace("\n", "\\n");
Related
I am trying to create shared libs for jenkins to build the app. When I am trying to pass the the json string from groovy function to shell block for build command execution. whereas json string passing without quotes. How to retain the quotes.
stage('build app') {
steps {
script {
build project:"TestApp.xcodeproj",
workspace: "TestApp.xcworkspace",
scheme: "Develop",
config: "Debug",
target: "{ "TestApp": { "info_plist": "TestApp/Info.plist", "profile_name": "Test App Debug (January 2021)", "app_id": "com.******.Debug" } }"
}
}
}
def build(Map buildParams) {
sh """#!/bin/bash -l
export XCODE_PROJ="${buildParams.project}"
export XCODE_WORKSPACE="${buildParams.workspace}"
export XCODE_BUILD_SCHEME="${buildParams.scheme}"
export XCODE_BUILD_CONFIGURATION="${buildParams.config}"
export XCODE_TARGET_JSON="${buildParams.target}"
#build App
fastlane build app
"""
}
Expecting the json string as it is in shell block with "Quotes". Whereas getting error expecting '}' found :. When i escape the quotes of json strings, getting, values without "quotes"
{ TestApp: { info_plist: TestApp/Info.plist, profile_name: Test App Debug (January 2021), app_id: com.******.Debug } }
which results fastlane throwing error invalid token. How to retain the quotes in shell block variable
Escaping the quotes in json string with backslash() is worked for me.
'{ "TestApp": { "info_plist": "TestApp/Info.plist", "profile_name": "Test App Debug (January 2021)", "app_id": "com.******.Debug" } }'
I am on visual studio 2019 for mac running a blazor server app with .net core 3.1 and Individual Authentication (In-app) turned on.
When i go to register and enter new users details i am presented with the following error when clicking the apply migrations button
In the appsettings.json i have the following set.
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=Test; user=SA; password=P#55word; Trusted_Connection=False;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using CMUI.Areas.Identity;
using CMUI.Data;
namespace CMUI
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
services.AddSingleton<WeatherForecastService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
}
The the SQL server i am running is 2019 mssql in docker using the following command
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=P#55word' -p 1433:1433 -d --name=mssqlserver2019 mcr.microsoft.com/mssql/server:2019-latest
The database is working okay as i can perform crud actions via an webapi in another solution using the same connection string. Not sure if this is a mac thing or if i have missed something silly.
Thanks.
You can try using the command line and navigating to the project root of the project that connects to that db, and then running dotnet ef database update which should run that migration and build your identity tables. Then fire the app up again and as long as it's connecting (which is looks like you are) you should be able to register users.
Further reading on migrations here. You may need to install the command line tools mentioned in this article.
I'm not familiar with VS for MacOS, but in the windows version you can go to Package Manager Console, make sure the default project in the console is set to your DB access project, and then run the command update-database. This might work for you as well.
I'm playing with vs code and a new asp.net core 2 webapi project.
When I debug it or run it without debugging I can access the site from the same machine using http://localhost:5000 but I can't work out (and haven't found anything for the new .net core 2 way of doing things) to allow me to change the listening url to something like http://0.0.0.0:5000 or even http://*:5000 so I can access the dev site from another machine on the network to test with IE (it's running on a Mac).
I have found plenty of examples for .net core <2 that show editing the Program.cs file and adding a host config but that file has changed now (simplified) and I can't find or work out a way to apply the same changes to the new layout.
As well as other questions and solutions like this that modify a hosting.json or project.json which both appear from my reasearch to have been removed or more replaced with the .csproj file. And again I have been unable to work out or find information on how to implement the same changes in the new .csproj file.
So could someone please point me in the right direction. I expected changing the host/listening url to be a LOT easier than this so I'm sure I am missing something obvious.
Here is my program.cs class in .NET Core 2.0 :
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace MyNamespace
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://*:5000")
.Build();
}
}
Note the .UseUrls("http://*:5000") that accept any incoming requests from port 5000. This is only used when you publish your application (right click on the projet, publish...).
When you run your application from VS 2017 (for exemple), VS takes the settings under Properties/launchSettings.json. You can edit this file anytime.
Hope this will help someone else because I wasted too much time on this!
Update:
I have just come across the Environment variables which seem a FAR better place to set this, also this is how I would have done it in VS 2017.
In JetBrains Rider they are under the build configs (Run dropdown then Edit Configurations...).
Under this window you can edit your build configurations. Find the one you use (I only have one currently but you might have a dev, staging etc...) and then find the Environment variables: (green) and click the button on the right (blue).
In the new window you can change the ASPNETCORE_URLS to what ever you require. For me I set it to http://*:5000 which causes it to pick up any incoming requests. For example localhost:5000 or 192.168.0.10:5000. I then pointed my dev.somedomain.com to 192.168.0.10:5000 and I can use https though NGINX to test on my dev site running on my Mac.
This also allows for easily changing it on a PC my PC basis by not checking in the JetBrains Rider settings.
Original Answer:
I have finally found the answer to this and #Métoule was right in the comment. I just didn't understand what it meant until now.
Basically the changes in the Program.cs in ASP.NET CORE 2.0 is just a way to hide away the stuff that will always be the same.
Instead of calling all these (like you needed to in Core 1):
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
You're just calling the ones you're likely to want to change:
.UseStartup<Startup>()
.Build();
SO you can still add UseUrls() as before just put it before the .Build();` like this:
.UseStartup<Startup>()
.UseUrls("http://192.168.2.10:5000")
.Build();
SO to change the Url of a brand new ASP.NET CORE 2 project I changed the Program class in the Program.cs file from:
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
To:
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://192.168.2.22:5000")
.Build();
}
Only adding the 3rd from last line: .UseUrls("http://192.168.2.22:5000")
As long as there are no firewalls in the way I can now access the above url from another machine on the network and see my dev site! :D
This may be a bit late to the conversation, but if you are still trying to get this to work with VS Code, you are able to set ENVIRONMENT variables directly in your VS Code launch.json.
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"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/netcoreapp2.0/vscode-env.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",
"ASPNETCORE_URLS": "http://*:5000"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
Minimal reproduction (in VS 15 Preview 2):
Create a new project using the "JavaScript -> Windows -> Universal -> Blank App (Universal Windows)" template.
Rename main.js to main.ts.
Add a tsconfig.json file to your project (see here for why).
Enter the following code in main.ts:
declare var foo: any;
foo();
Go to "Debug -> Windows -> Exception Settings" and check "JavaScript Runtime Exceptions".
Click the green "Run on Local Machine" button.
An error message appears:
Unable to activate Windows Store app [...]. The wwahost.exe process started, but the activation request failed with error 'Windows was unable to communicate with the target application. This usually indicates that the target application's process aborted. More information may be available in the Debug pane of the Output window (Debug->Window->Output)'.
Expected behavior: the IDE should break on foo();.
There is a work-around for VS 2015 Update 3 (s/o to #minestarks on GitHub):
I assume you're running in an English locale here, otherwise I don't think the workaround is applicable.
Close VS.
In an administrator command prompt:
cd %ProgramFiles(x86)%\msbuild\microsoft\visualstudio\v14.0\typescript
mkdir en
copy *.xaml en
copy TypeScript.Tasks.dll en\TypeScript.Tasks.resources.dll
Now open your UWP project again, the TS files should be visible and building when you build your project.
Make sure Typescript for VS2015 is installed, and try with other codes. I tried with following codes:
function buildName(firstName: string, lastName: string) {
return firstName + " " + lastName;
}
let result3 = buildName("Bob", "Adams");
Make sure your "tsconfig" is correct:
{
"compilerOptions":
{
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true
},
"files": [
"main.ts"
]
}
Make sure your main.js and main.js.map files are generated correctly(show all files in solution explorer to see these two files):
main.js:
function buildName(firstName, lastName) {
return firstName + " " + lastName;
}
var result3 = buildName("Bob", "Adams");
//# sourceMappingURL=main.js.map
main.js.map:
{"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":"AAAC,mBAAmB,SAAiB,EAAE,QAAgB;IACnD,MAAM,CAAC,SAAS,GAAG,GAAG,GAAG,QAAQ,CAAC;AACtC,CAAC;AAED,IAAI,OAAO,GAAG,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC"}
And here is my basic demo project:TypescriptDemo
Here is a snippet from my gruntjs file in a vs2013 web project. What I am seeing is adding the last line in the initconfig to load the settings stops showing the tasks in the VS2013 Task Runner Explorer. As soon as comment out that line the Task Runner Explorer enumerates my tasks. There are no errors in the output window for the Task Runner ExplorerI .
I can run my gruntfile.js fine using the grunt cli.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
target: grunt.config.get('target'),
settings: grunt.file.readJSON('config/' + grunt.option('target') + '.json'), //problematic line
karma: {
unit: {
configFile: 'karma.conf.js'
}
},
I had a problem with grunt.file.readJSON and I solved it by giving my option a self invoked function which checked to see if the file even exists. Something like:
settings: function () {
if (grunt.file.exists('config/' + grunt.option('target') + '.json')) {
return grunt.file.readJSON('config/' + grunt.option('target') + '.json')
}
return '';
}()