In an ASP .NET Core application, there is no default web.config file in the project. However, when I run dotnet publish, there is a web.config file present in the output directory.
But what if I want to modify some web.config values, and have those merged into the published web.config?
It seems I just wasn't paying enough attention. If I make a web.config file in my project with new properties, it is merged into the generated web.config on publish.
Related
I want to create a web deployment package which leaves certain existing directories alone when deploying, e.g. a "logs" folder. Currently the package deletes/overwrites all existing files.
I can exclude the folder by adding extra parameters when executing the foo.deploy.cmd in the package, eg.:
.\foo.deploy.cmd /T """-skip:Directory=\\logs"""
This seem to work. But I can't figure out how to include this configuration in the package itself so it will be applied automatically.
I have a Asp.net Core website on .net framework 4.7. I use Visual studio 2019 with a pubxml publish profile.
I have tried adding MsDeploySkipRules to the pubxml but they don't seem to be passed to the package parameters. I am unsure if MsDeploySkipRules should work with "Web Deploy Package" or only with "Web Deploy"?
Edit: The problem may be related to I'm using Asp.net core. The MsDeploySkipRules seem to be applied in a regular asp.net (added in the generated deploy.cmd script) project but not if I insert the same in an asp.net core project file.
You could try to add the below code in your .csproj file to skip the folder at the time of publishing.
<ItemGroup>
<Content Remove="wwwroot\test\**" />
</ItemGroup>
also ste the delte existing file to true:
ASP.NET Core: Exclude or include files on publish
I am trying to find a way to run MVC6 application on IIS but without actually doing the publish. I am not sure if that is possible, and if not will it be possible in the future?
I would like to have similar behavior like on previous versions where I could easily debug my code and make changes while the application is running under IIS.
From your original question (emphasis added):
I am trying to find a way to run MVC6 application on IIS but without actually doing the publish.
From your comment to tugberk (emphasis added):
Right now every time when I make a change I need to call that dnu publish command in order to see my changes on IIS. I would like to see them only by doing rebuild.
Answer and reasons
You'll need to publish. There are at least two reasons:
IIS needs build output and
IIS needs a web.config file.
IIS might need a few other things too, about which I'm not aware. So, you'll need to publish. This isn't a big deal: after the onetime setup, publish doesn't take much longer than rebuild does.
Why do you need to publish?
In Visual Studio 2015, if you build an ASP.NET 5 web app, there will be no build output under your solution's directory, and IIS needs build output. By default Roslyn only runs code analysis without emitting build output.
You can change that default, so that Roslyn does emit build output, but that won't produce the web.config file that IIS needs. By going to View > Project Properties > Build and checking "Produce outputs on build", Roslyn will emit output to the artifacts directory. E.g:
artifacts/bin/MyWebApp/Debug/MyWebApp.1.0.0.nupkg
artifacts/bin/MyWebApp/Debug/MyWebApp.1.0.0.symbols.nupkg
artifacts/bin/MyWebApp/Debug/app/project.json
artifacts/bin/MyWebApp/Debug/dnx451/MyWebApp.dll
artifacts/bin/MyWebApp/Debug/dnx451/MyWebApp.pdb
artifacts/bin/MyWebApp/Debug/dnx451/MyWebApp.xml
artifacts/bin/MyWebApp/Debug/dnxcore50/MyWebApp.dll
artifacts/bin/MyWebApp/Debug/dnxcore50/MyWebApp.pdb
artifacts/bin/MyWebApp/Debug/dnxcore50/MyWebApp.xml
If you point IIS at the artifacts directory, you'll now have the problem of having neither a wwwroot nor a web.config.
So, you need to publish (or work out some other convoluted solution) for IIS to work with ASP.NET 5. There is a onetime setup if you want to publish from Visual Studio to a local IIS website. After the onetime setup, you can make changes to your code and publish in two clicks. Here's the onetime setup:
Right click the project.
Choose Publish.
Select File System and add a profile name (e.g. inetpub).
Change the target location to C:\inetpub\MyWebApp
In Settings, select appropriate settings. E.g.
Configuration: Debug
Target DNX Version: dnx-clr-win-x64.1.0.0-beta4
Click Publish.
Once publish completes, point IIS at C:\inetpub\MyWebApp\wwwroot and you will be able to browse to the web site. Further to the point, you can now change your code, publish in two clicks, and refresh your IIS site to see the changes.
Some gotchas
If you do choose to publish to inetpub, be sure to run Visual Studio as administrator, lest you receive an insufficient permissions error.
If you accept the default publish location (instead of using inetpub as shown above) watch out for path too long errors (i.e. > 260 characters.)
Final thoughts
Why not use Visual Studio and Debug > Start without debugging during development. With Roslyn and Visual Studio 2015, you can make changes to the code and see those changes by refreshing the web browser. No rebuild is necessary. It's a much nicer workflow.
It's possible. Under the root of your project (project.json directory), run the following command:
dnu publish --runtime active --out bin/artifacts
Once the publish is done, you have some stuff under bin/artifacts folder. Point IIS application pool to bin/artifacts/wwwroot folder we have just created and it should work. Keep in mind that you at least need .NET 4.5.1.
I'm assuming this is a development on IIS question. It's doable but it requires some work. The reason IIS doesn't work out of the box without a publish is because there is no user profile setup on app pools by default. The simplest thing you can do is to enable the user profile on the app pool, that will allow IIS to find the runtime in the user profile folder. On top of that, you require a web.config to specify which version of the runtime to use (dnu publish generates this for you so if you want, you can do a publish and copy the runtime folder). After doing that, pointing IIS to the wwwroot should just work (assuming you setup the right web.config with the right runtime and the right bitness).
You also need the correct AspNet.Loader.dll in the bin folder. If you use visual studio, it'll copy it in the right place.
Based on davidfowl answer i ran ASP.NET MVC6 on IIS without publishing application. But i still can't start debug it by F5(only by attaching to w3wp.exe).
Anyway i hope it would be helpful:
In the root of the project add "packages" directory(or name it whatever you like).
In global.json file add "packages": "packages". e.g.:
{
"projects": [
"src",
"test",
"wrap"
],
"sdk": {
"version": "1.0.0-beta4"
},
"packages": "packages" // <--
}
Packages will be now stored in this directory.
Create a "runtimes" directory in the root of your project.
Copy a runtimes from %userprofile%/.dnx/runtimes to /path/to/your/project/runtimes
Create a web.config in wwwroot of you project. e.g.:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="bootstrapper-version" value="1.0.0-beta4" />
<add key="dnx-version" value="1.0.0-beta4" />
<add key="dnx-clr" value="clr" />
<add key="dnx-app-base" value=".." />
<add key="runtime-path" value="../../../runtimes" />
</appSettings>
</configuration>
Create web application in IIS and point it to your project wwwroot.
My project directory structure:
Projects/
vNext/
packages/
runtimes/
dnx-clr-win-x64.1.0.0-beta4/
dnx-clr-win-x86.1.0.0-beta4/
...
src/
vNext/
wwwroot/ <-- IIS web application points here
web.config
...
project.json
...
global.json
vNext.sln
...
After this you will be able to attach to w3wp.exe and debug your application running under IIS.
I have WCF Service Library project and have configured slow cheetah extension for transforming .config files.
When I run publish on the project the build output produce in bin folder appropriate dll file for the service and NameOfService.dll.config file which is transformed correctly.
The publish process also produce .svc and web.config file. The issue is that the web.config file is not transformed.
Is it possible to get also web.config file transformed by this process and how ?
I've bene doing well with .NET config transforms. I have them in place now on a class library for data usage and a WPF app.
However, when I attempt to set them up with an ASP.NET WebAPI project, something strange seems to happen.
The config file never shows up in my bin directory, and so the web.config always shows as the pre-formed config file.
If I run MSbuild with parameters of "/t:TransformWebConfig /pConfiguration=Test" on the csproj, I see the following:
CollectWebConfigsToTransform: Found The following for Config
tranformation: Areas\HelpPage\Views\Web.config, Web.config,
Views\Web.config, bin\Web.config PreTransformWebConfig: Skip copying
Web.config to obj\Test\TransformWebConfig\original\Web.config, File
obj\Test\TransformWebConfig\original\Web.config is up to date Skip
copying C:\Users\killesj1\Repositories\MRP Trunk\Macro
Projects\VEUploader\src\app\VEUploader.WebAPI\Web.config to
obj\Test\TransformWebConfig\original\bin\Web.config, File
obj\Test\TransformWebConfig\original\bin\Web. config is up to date
TransformWebConfigCore: Skipping target "TransformWebConfigCore"
because all output files are up-to-date with respect to the input
files. TransformWebConfigCore: Skipping target
"TransformWebConfigCore" because all output files are up-to-date with
respect to the input files. PostTransformWebConfig: Transformed
Web.config using Web.Test.config into
obj\Test\TransformWebConfig\transformed\Web.config. Transformed
C:\Users\killesj1\Repositories\MRP Trunk\Macro
Projects\VEUploader\src\app\VEUploader.WebAPI\Web.config using
C:\Users\killesj1\Repositories\MRP Trunk\Macro
Projects\VEUploader\src\app\VEUploader.WebAPI\Web.Test .config into
obj\Test\TransformWebConfig\transformed\bin\Web.config.
It appears that the transformation is tranforming the file, but somehow it's not making its way back into the bin directory, where the old Web.config remains.
Is this normal? How might I get this to behave similarly to other web transforms?
I had a similar problem, deploying Test projects on Appveyor that weren't being transformed, and followed the advice in the link below and now everything works nicely. I had all my projects set up to do xxx.config transforms in the [Target Name="AfterBuild"] and it worked perfectly on my local dev machine, but on pushing the code to Appveyor, the tests would fail because of untransformed files etc. Basically, move everything to the [Target Name="BeforeBuild"] and see if that helps.
MSBuild - how to force "AfterBuild" target when I do deployment?
web.config normally located in the root and is not copied to bin subfolder. To apply transforms you need to have some template web.config and transform it to root web.config.
E.g. see https://stackoverflow.com/a/16239488/52277 and Use Visual Studio web.config transform for debugging
I am using NHibernate in a DAL layer dll. Local config file(app.config) is being used for db connection. This DAL component can be used in 2 different exe's and a NUnit test harness. Business requirement from Client is to have config information reside in exe's app.config file.
Is there a way to configure NHibernate to look for an app.config file based on the exe that it is compiled with?
Then in the NUnit test harness, look for a default config file?
Thanks,
Marc
As Dan hinted, NHibernate's main config section can either be in a standalone hibernate.cfg.xml, OR it can be put in the application's config file. If you want NHibernate's core config to vary by the currently executing environment (different apps, or during testing), you can go the app.config route. If no hibernate.cfg.xml file is found, NHibernate is going to look in the currently executing app's app.config file.
Here is an example of putting the NHibernate config in an app.config file: http://www.martinwilley.com/net/code/nhibernate/appconfig.html