In my ASP.NET WebAPI (not Core!) project, I would like to use the SDK-based csproj format. I converted the project and got it to build:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<OutputType>Library</OutputType>
</PropertyGroup>
Now when I run it using IIS Express, I get:
Waiting for the IIS Express worker process to start…
Worker process has been started: 22108
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Code\MyWebApp\MyWebApp\bin\Debug\net461\'.
Failed to run as a self-contained app. If this should be a framework-dependent app, add the C:\Code\MyWebApp\MyWebApp\bin\Debug\net461\MyWebApp.runtimeconfig.json file specifying the appropriate framework.
I've seen this answer to a similar question that suggests adding a .runtime.config file but I believe it is only required for .NET Core apps.
I don't want to migrate to .NET Core at this point. All I wanted was to use the new project format to get rid of some nasty binding redirects. I.e. I only wanted to change my build tooling and leave everything as is at run time.
My launchsettings.json:
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59119",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true
}
}
}
These are the changes I made: Pull request
The ASP.NET team have responded:
This is not possible, sdk-based projects are not suited for traditional aspnet/webapi projects and it is likely you'll see a long trail of issues if you try to use them.
I was so close to getting it to work!
Related
I am attempting to use SFML for my next project, however I have yet to find reliable information on how to install SFML for MinGW, the page on the main SFML website is for using code::blocks, and I would prefer to keep using VS Code if I could. Additionally all of the tutorials for visual studio are for older versions where the UI is much different. I was hoping that someone who has installed it could guide me through the steps they used to install it. Thanks.
I am on Windows.
Just to be clear, I have never used Visual Studio Code, but it supports Nuget Package Manager, so it should work the same as in the 'normal' Visual Studio. So after creating new project:
Your should be getting/installing Nuget Package Manager from here.
Then according to answers to this question, you should be able to Press Ctrl+P or Ctrl+Shift+P and search for SFML packages, and choose version 2.5.1.
There are five modules: Audio, Graphics, Network, System and Window, choose what you need or install all five.
As I said at the begining, I do not have a way to test it, but it should work.
This question is fairly old at this point but for anyone in the future wondering how I solved it, I ended up switching compilers to Clang and creating a .bat file the just runs clang++ and links the SFML lib directory. (SFML GCC-64 worked fine with Clang)
To fix any errors in VS Code, you can add SFML to the workspace config
in .vscode/c_cpp_properties.json:
add or edit a field called "configurations" (should be an array), and add the following:
"configurations": [
{
"name": "SFML",
"intelliSenseMode": "clang-x64",
"includePath": ["${defaultInclude}", "C:/libs/SFML/GCC-64-Bit/SFML-2.5.1/include"],
"compilerPath": "C:/msys64/mingw64/bin/clang++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"browse": {
"path": ["${workspaceFolder}"],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
]
You'll have to change some of the paths to fit your setup, and you could very well put this in your global C++ configuration.
Finally, make sure that the needed DLLs are copied to your compilation output directory
I installed docfx.console through the nuget package manager (visual studios 2017 15.7.3) into a test project. My project is a .net library with a singular class with a bit of xml documentation. When I build the project it creates a _site file with a .html file but no documentation. It also generates an api, apidoc and articles folder and a docfx.json file.
The project throws the warning: Unable to find either toc.yml or toc.md inside obj/api/. Make sure the file is included in config file docfx.json!
I found a few similar issues in github which advised setting my visual studio version to 2015, however this solution doesn't appear to work with docfx.console as far as I can tell. Does anyone know how I might be able to correct this issue? Thank you
I also stumbled upon this issue when I was documenting an existing VB.net solution. Without knowing what your docfx.json file looks like or whether your .NET library is written in C# or VB.net, I can only provide a answer that fixed my issue and maybe will help with yours.
For me when installing docfx via nuget, the docfx.json file is set to be used with C# projects and not VB.Net projects by default.
I easily fixed this by modifying the docfx.json file and changing the metadata file source extension to search for *.vbproj:
"metadata": [
{
"src": [
{
"files": [
"*.vbproj"
],
"cwd": ".",
"exclude": [
"**/obj/**",
"**/bin/**",
"_site/**"
]
}
],
"dest": "obj/api"
}],
Is it possible to suppress errors in Visual Studio (when working with TypeScript)?
Specifically I'd like to suppress the is declared but never used-error. When debugging I need to comment out some code every once in a while, but Visual Studio refuses to build the project if I have declared a function I'm not using.
Why is that an error to begin with? Shouldn't it be a warning?
You should use a tsconfig.json file, more information here:
http://www.typescriptlang.org/docs/handbook/tsconfig-json.html
It might take some time to get it configured the way you have your project configured now, but there is a setting to not error when there are unused locals:
{
"compilerOptions": {
"noUnusedLocals": false
}
}
There are also a couple other settings, noUnusedParameters, allowUnsedLabels and allowUnreachableCode which may help you.
The schema for the JSON file is available here: http://json.schemastore.org/tsconfig
Visual Studio should know that the JSON file is a tsconfig file and provide you with IntelliSense information from that schema file.
If using a csproj -file, you can get rid of the is declared but never used -error by removing the line
<TypeScriptNoUnusedLocals>True</TypeScriptNoUnusedLocals>
or changing it to
<TypeScriptNoUnusedLocals>False</TypeScriptNoUnusedLocals>
Some other settings for suppressing errors:
<TypeScriptAllowUnreachableCode>True</TypeScriptAllowUnreachableCode>
<TypeScriptNoUnusedParameters>False</TypeScriptNoUnusedParameters>
<TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
I have both a Xamarin Client and Asp Core Web API that need to reference the same project, which will be used as a Portable Class Library. Sounds simple, but I'll take you through my process. The PCL is just a Model so I can use the same classes for transporting JSON between them).
Process:
I create a standard .NET PCL, then attempt to reference it in my Xamarin project. Xamarin is unable to add it since "Portable Library projects can only reference other Portable Library projects". Ok, no worries. I'll create one of those and try it.
I Create a "Class Library (Portable)" dll instead. I configure the project so it matches the same targets (one of them being "ASP.NET Core 1.0") as my Xamarin project, and it imports perfectly. I can use it fine - yay!
Alright, since the "Class Library (Portable)" dll targets ASP.NET Core 1.0, I shouldn't have any issues referencing it in my Web API project. I add it to my project.json...
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
],
"dependencies": {
"TestClassLibraryPortableDll": {
"target": "project"
}
}
}
},
and all is well. BUT, I can't actually refer to the namespace from within my WebAPI project.
This is as far as I have gotten, after trying so many different things. Standard .NET dll's, ASP.NET Core class libraries, .NET Platform Standard conversions... all sorts.
I feel like I'm missing a very simple but very important step. Any ideas?
My WebAPI will be deployed on Linux, if that helps. Does this mean I have to go with the new netstandard? It seems dodgy at best (and has very little documentation).
I've also posted in the ASP.NET Core forums, and was told this:
If you need to target linux, then you need to target netstandard and
so can only use netstandard libraries. You need to change your model
(MUST be a netstandard library) and add it to the dependencies.
And here's my reply:
Ok, so I create a NetStandard PCL as my Model class. This references
perfectly on my WebAPI project, but not on my Xamarin project.
Error Image.
This happens AFTER I convert my Xamarin project to a netstandard
library, as detailed in this post.
Does anyone have any suggestions? I may just have to have a set of
classes that I can include in each of the projects (or perhaps keep
the models in my WebAPI project, and reference it from my Xamarin, if
possible) just so I can move on and get some work done.
We have Visual Studio 2010 SP1 and Async CTP (SP1 refresh) installed.
A solution with projects that use async/await keywords builds OK when build from VS IDE.
Also when built with devenv /build "Debug" solution.sln everything is OK.
However msbuild #commands.rsp solution.sln reports:
File.xaml.cs(123): error CS1993: Cannot find all types required by the 'async' modifier. Are you targeting the wrong framework version, or missing a reference to an assembly?
commands.rsp looks like this:
/nologo
/p:Configuration=Debug
/m:3
/fileLogger
Any clues?
Please, refer to the discussion here: http://social.msdn.microsoft.com/Forums/uk-UA/async/thread/3d491cb0-a19f-4faf-80a6-5fd05e4e06db
There are 2 points to be clarified in order to understand better your problem:
Environment: did you install VS11 side-by-side with VS 2010+Async CTP?
Your project: do you have XAML with user controls and "clr-namespace" in your project?
I will cite the preliminary conclusion by SERware from the discussion on the MS forum:
I think it has to do with the order in which the XAML projects
compile assemblies when referring to classes of the library itself. In
this case, the XAML Loader try to compile this classes before having
reference to the Async CTP library. So, the keyword "async" is not
recognized.
Personally I am going to see whether it is possible to split the assembly in order to resolve the order of the compilation of the dependencies in XAML
Added after further investigation:
As I have found out, the explanation is even more disappointing: the .NET 4.5 (Beta) replaces the .NET 4.0. Besides, the signatures of the async/wait related types have been internally changed. Therefore there is no way so far to use simultaneously VS 2010+AsyncATP and VS11 Beta. – Yuri S. 2 mins ago
I was hit by this myself and for various reasons I can't upgrade the projects to .NET 4.5 so I had to develop a workaround.
Since this is only a problem for XAML projects that has a xmlns declaration pointing to itself I'm able to use async on all the other projects that are referenced. This means my architecture is still utilizing async/await and is prepared for the move to .NET 4.5 later.
But in the affected XAML projects, I just manually implement (poorly) the await things otherwise done by the compiler.
So code that was this clean before:
try
{
var foo = GetFoo();
foo.DoStuff();
var data = await foo.GetDataAsync();
bar.WorkOnData(data);
}
catch (Exception ex)
{
// Logging, throw up a popup, whatever...
HandleError("Failed to get data", ex);
}
Now becomes this:
var foo = GetFoo();
foo.DoStuff();
var getDataTask = foo.GetDataAsync();
getDataTask.ContinueWith(t =>
{
if (t.IsFaulted)
{
// Logging, throw up a popup, whatever...
HandleError("Failed to get data", t.Exception);
return;
}
if (t.Status == TaskStatus.RanToCompletion)
{
bar.WorkOnData(t.Result);
}
});
Not ideal of course, and this is the exact thing that async/await was created to solve. But it does work as a short-term workaround at least for simple uses of await.