Blazer Server App - Add web.config settings - web-config

I have a Blazor Server app that is running under IIS. I see that it generates a web.config file upon publish with some settings in it.
I need to add some more settings to the web.config as they are used by another component (asp.net 4 app). Does anyone know which file I need to create/modify in order to be able to add these values.
At this stage I do not need to use transforms on the web.config, but it would be nice to know this as well.

What I found is that the web.config works as per Asp.Net Core documentation. In brief for a Blazor server app hosted under IIS (this is my understanding)
If there is no web.config existing in the root of the project directory, one is created during the build and copied to the bin directory. It will contain default information.
If a web.config exists in the root of the project directory, it is copied to the bin folder unmodified (note: it requires some default settings inside).
If transforms exist, they will be applied.
I didn't realise that the web.config is created if it did not exist hence my original question.
Also, I have not been able to get transforms to work yet.

I found that if you publish the project the web.config in the root gets ignored and uses the auto-generated one.
Adding this to my blazor project file solved it and can see the web.config getting published to Azure now:
<PropertyGroup>
<PublishIISAssets>true</PublishIISAssets>

Related

Why web.<environment>.config is present after File Transform in release pipeline

In my release pipeline I am using File Transform option for my web.config.
I have web.config and web.staging.config
File transform is working and changes are applied in web.config but why web.staging.config is still present in the final deployed package.
Am I missing any configuration or this a normal behaviour?
For this issue , with XML file transformation, the web.xxx.config file is required. The transform will be applied when publish web app to web deploy package or publish to server directly per to the configuration.
As stated in the documentation: You need to create a Web Application package with the necessary configuration and transform files.
So if you want to removing all config transforms, as a workaround , you could add a Delete-files task in the end to remove all configuration files. For example:
Source Folder:
$(wwwRoot)\
Contents:
**\*.staging.config
Here is a case with similar issue , you can refer to it for details.

TDS File Replacement

I want to deploy some front end assets to the local web root of a site using file replacement. I can't seem to get it to work with a relative path in the target location field though. Is it possible to do this though tds or should I use a post build event instead?
The reason these assets aren't included in a project is that they are part of a third party solution but we still want this tracked in source control to try to make the project setup easier.
Most developer machines will be set up the same way for this project with the same file structure but I think it's a little more flexible if I can make the target a relative path so I don't need to worry about differences like drive letters and such.
The folder structure is as follows:
repo
folderToCopy
sitecore
webroot
I have tried the following using ..'s based on what tds changed my source location to be while using the "Make selected Source Location relative" option (changed it from an absolute path to ..\folderToCopy\):
../../Sitecore/Website
/../../Sitecore/Website
..\..\Sitecore\Website
\..\..\Sitecore\Website
From my understanding, TDS does the file replacement based on the files published from the associated Website project.
You can then have relative replacements such as the following:
<Replacement Include=".\assets\folderToCopy\myFile.txt">
<TargetPath>.\assets\targetFolder\myFile.txt</TargetPath>
<IsFolder>False</IsFolder>
<IsRelative>True</IsRelative>
</Replacement>
I have not been able to successfully get TDS to use the file replacement with files that are in source control but not in the project.
My suggestion would be to set up a build event that will copy these files to the correct location, or to create a nuget feed for them and pull them in as nuget references.

Zend framework deployment in Bluemix

We would like to deploy Zend framework in Bluemix. We used the recommended buildpack https://github.com/zendtech/zend-server-php-buildpack-bluemix, however it does not help. For deployment we need to change Document Root to their 'public' folder.
In practice it can be done via changing apache configs or adding htaccess file. So we are not able changing the apache configs, therefore we added htaccess file for it. The folder has been created and via htaccess the document root has been changed (it works). But when the framework has been pushed it does not work (The blank page is appeared without PHP run-time errors).
There is a environment variable that configures the document root for an application using this buildpack:
ZEND_DOCUMENT_ROOT.
Using this instead of the htaccess rewrite rules should work.

Applying web.config transformations locally

I have a transform for my web.config that currently works if I publish to Azure, but it's not working locally when I build/run. How can I go about "Publishing" locally so the Local transformations are applied to my web.config on my dev box?
Currently I right-click > publish to Azure, do I need to create a new publish profile for my local box? Is there any way to get the transforms to work on Build instead?
It depends on which dev server you are using. As #Citronas said on this answer:
It depends on how you debug. If you are using Cassini, afaik your
web.config contents will be read regardless of the selected solution
configuration (e.g. Debug or Release).
If you are debugging with your
local IIS, it depends on what you have set the path in the IIS to. If
you have set it to your source code directory, you need to write your
local settings into your web.config. If you publish your code into a
local directory and set the IIS path accordingly, you can use
web.config transforms. (You said, that your web.config transforms are
working)
You do not need to publish locally (even though you can do that, publish to local IIS then attach the debugger to the worker process of the application pool) since it is annoying. The easiest way is to simple have your debug settings in the web.config file and then apply transforms for your "publishable" environments.
In short: do not use transforms for debug, only for publishing. Use the regular web.config to debug.

Unity Configuration using multiple config files

Is there a way to configure a container in multiple configuration files?
For instance, I want to register types for a container in a web.config file located at the root and also register types for the same container (and others containers) in the web.config file of sub-folders.
And also register other types for others containers in a company.config file in path C:\Company\Framework\Configs.
When I try to do this I get a ConfigurationError stating that the entry for the container has already been added.
EDIT: any suggestions here
http://unity.codeplex.com/Thread/View.aspx?ThreadId=23230
any more suggestions for sample code ?
I have a similar question posted here: WCF + Unity nested web.config problem
I have a web application with a subdirectory 'Services' which contains WCF services.
This services folder also has a web.config file containing my WCF configuration. That doesn't seem to be a problem for WCF.
The same web.config also has unity configuration for use inside my services. But i'm unable to load this configuration using 'GetSection'
If I move my unity configuration to the root web.config, everythings works fine.