AppSettings for different environments in Visual Studio 2022 and .Net 6 - c#

Visual Studio 2022 using .Net 6.
Im going through a few tutorials and one thing ive come across has me a little stomped regarding the usage of appSettings.json which has replaced web.config.
In prior versions i could create a new configuration within the Configuration Manager option and set new environments i.e. Home, Office, Staging and left the Release one as is.
Following this i could use the dropdown to switch between environments and i used to expand the web.config to view these files/settings for the appropriate environment.
In the current version i see appSettings.json and carried out the same steps but no new configs appear (even if i show all hidden files) when i expand appSettings.json.
After researching around im a little confused as some parts are targeting .Net Core 3.0 or similar, other threads continue to use the web.config so not sure if something has changed between versions for .Net 6 and appSettings.json but how do i configure to use different environments?

Related

.NET Framework version causing different behavior between two different machines?

I'm currently trying to debug a weird issue I'm having with some RESTful API calls. I built an Angular 2 scaffold and used the publish feature to create a standalone build which users can run by opening a command prompt and typing in "project --debug" -> this will start the scaffold service and users can submit API calls to retrieve data from files. This works perfectly fine on my machine and I can make the API calls just fine, but I have another computer where the results are different. The other computer always fails and lands in an Exception block when accessing a specific type of file.
I'm wondering if this may have to do with some kind of version mismatch/difference on the .NET Frameworks and/or Microsoft Visual C++ redistributables. The published build (original computer) was built using .NET 4.5.1 while the other computer only has 4.6.1 installed.
Has anyone encountered a similar situation where the exact same build yields different results? I'm currently uninstalling versions of .NET and redistributables to test this hunch out but I'm curious if some of you may have had a similar experience.
Seems like my issue is related to the Microsoft Visual C++ 2015 Redistributables - I removed the 2015 redistributables from the original machine (because it turns on the other machine did not have them), and I received the same results. Going deeper, I'm guessing this is because one of the DLLs was built using the 2015 redistributables.

What are the differences between these project types, and how can I fix the difference?

We are in the process of migrating from VS2012 to VS2015, and I'm running into an issue with hosting one of the web projects of a different "web project" icon.
Example project types:
1 is a successfully hosted web site
2, 4, and 5 are c# class libraries
3 is a test project
6 is a website... but is clearly different than #1. I have not successfully hosted this project at a virtual directory in VS2015, where it is in VS2012. How is #1 different from #6? I see #1 has a csproj file, #6 does not. Also the "property" windows are significantly different from the project types.
1 VS2012
1 VS2015
6 VS2012
6 2015
As you can see the property pages of the two VSes and two different project types differ pretty significantly.
My #6 project in VS2012 is hosted at http://localhost:9999/VirtualDirectory/ so its services can be accessed as (example):
http://localhost:9999/VirtualDirectory/Service1.svc
However in VS2015, I can't get it hosted under http://localhost:9999/VirtualDirectory/Service1.svc but rather only http://localhost:9999/Service1.svc I've tried changing the radio button from "use default server" to "use custom server" and specifying the base URL, however the services do not resolve when attempting to host in this manner.
What is the difference between #1 and #6 project type? What are my options for fixing my hosting differences between VS2012 and VS2015?
Right now I can change my end point connections in my web config to rather than point to http://localhost:9999/VirtualDirectory/Service1.svc instead point to http://localhost:9999/Service1.svc, but this breaks the endpoints for VS2012. Ideally I'd like to have the project configured in such a way that it works seamlessly and without config changes between running the solution in VS2012 and VS2015.
I believe 1 is a web application and 6 is a website.

Multiple Publishing web.configs in Visual Studio 2010

In my settings, I have two String settings and one connection string. These obviously show and are changeable in the web.config.
On top of that, not in the settings, but in the web.config, I have my entity framework connection String.
I also have 4 different publishing profiles (Addresses to publish my website to)
However: They all run off the same config file. So I have to change it manually before each publish. And if i forget/get it wrong, the entire site siezes to work.
Is there any way, to link publish specific web.config files. So that each publish profile generates the correct version, with its correct values/connection strings.
Ive come accross transforms, and pubxml, but nothing seems to make sense or work, or even be compatible with VS 2010.
If anyone can link or explain the path i should be taking to achieve this, i would be gratefully happy. I have spent days trying.
You can create a new configuration in the Configuration Manager and then create the corresponding config for that profile.
When deploying, if you change the configuration to the correct one, it will then pick up the appropriate config.
How to: Transform Web.config When Deploying a Web Application Project
I would take a second look at web config transformations - it was built for exactly this and is most definitely supported in VS 2010. Alternatively I have worked with a deployment setup where there was a custom utility that did exactly what web config transforms does by running as a build task. Using the two I would still recommend web config transformations due to it being well documented.
The .pubxml and profile-oriented transforms are available in VS2010 through the Azure SDK Bundle. Here's how to do it:
Have VS2010 installed. I'm using VS2010 Ultimate RTM (had to set up a new machine).
Install the Azure SDK. I'm doing this through the Web Platform Installer; it looks like the last Azure SDK for VS2010 was 2.1. This includes SP1 (if you don't have it already), a further hotfix, and the out-of-band tooling update to support .pubxml, as well as a bunch of other things. If you just want the VS components, I think you can find them at http://azure.microsoft.com/en-us/downloads/archive-net-downloads/ under July 2013 (Version 2.1)
At this point, you can create publish profiles as many of the newer blog posts show:
And add transforms for them:
And preview the transforming effects of each profile's transform (which does take into account the Debug/Release ones as well):

How to Deploy multiple versions from one Project

I have an .Net 4.0 solution, and i use Visual Studio 2010.
in that soulution there is an startup project. I deploy the Project with the Webdeployment method, onto the IIS, the client can then go to the publish.html of the corresponding website, and install the application.
My problem starts when i try to release two different versions of that prooduct and try to install both on the same machine, then the installer thinks that the application is already installed. (after i install the first version of the product, the installer then complains that there already is an app with this name but i changed the product name)
How can i publish two different versions of my project, on two seperate websites? and have them install on the same machine at the same time?
I have found the solution for this problem, as the commenter Franck pointed out, there has to be some sort of distinction between those apps.
So i made just different keys for the different Variations i wanted to deploy:
Rightclick on the Startup project -> Properties -> Tab: Signning-> here one can create certificates for as many Variatons as one pleases, be sure to save the different certificates for later deployments!
when deploying a certain variation i then simply swap the file, and then msdeploy "thinks" it manages different apps.

How to make a setup installer? For asp.net mvc 2.0, cmd line applications and webservices

I am wondering how can I make a setup project for each of these projects
Asp.net mvc 2.0
C# cmd line
Application C# web-service
I am using VS 2010 ultimate and I know that I can use the the free edition of install shield for at least the cmd line application. I am not sure about the other 2. I also know about the setup project that you can use. I just need a lot more than the basics so I am not sure how to make either one do these things.
So here is some criteria that each of my setups should be able to do.
Asp.net mvc 2.0 criteria
free (I really don't want to pay for an installer - you can list them just so I am aware of them).
Terms of service
Ability to force a user to setup certain settings. Like connection string, smtp settings. So they should be able to type it in through the setup wizard and the web.config should be updated based on this.
When it installs the stuff it should all be .dlls for all the C# code.
C# cmd line criteria
All criteria as above
I am not sure if this has to be done in the code but I have a html file that contains a template for a message. The path to this file is in the web.config so I a person needs to set this path each time they install it. I tried to do this in code but I could not figure out how to make it find the right path in development and the right path in production. It seems like If you run in VS the path is different.
Web-service
Pretty much everything I covered in the first 2 ones.
Thanks
If I were you, I would choose WiX as a platform for your installers for all these applications. Some reasoning behind this:
it is XML-based, that is, friendly to source control, diffing and merging
it has rich set of tools for most of scenarios you might need (harvesting lots of files, creating upgrades and patches, creating multi-lingual installs, etc.)
it is free and open source
it is production-ready (at least, version 3.0 - later versions are still in beta)
it is used by Microsoft to create installations for such products like MS Office
it has rich community at wix-users#lists.sourceforge.net and StackOverflow
it integrates into the VS like a charm
it is friendly to build engines like NAnt and MSBuild
VS setup project is not my choice because:
it is very limited in set of features-
it encourages bad practices like Installer classes
finally, it was retired by Microsoft
I'm not familiar with InstallShield Limited edition, though.
Hope this overview will help you finding the best option for your case.

Categories