How to rename web.config transforms - asp.net-mvc-5

I am working in an ASP.net MVC 5 solution in Visual Studio 2015. I have the following web.config
How do I rename those to be
Web.Integration.config
Web.Staging.config
Web.Production.config
When I right-click on those, I don't get a rename option!

You can copy the files, rename them and manually edit the .csproj file to include them (replacing the generated ones) like below:
<Content Include="Web.Integration.config">
<DependentUpon>Web.config</DependentUpon>
<SubType>Designer</SubType>
</Content>
<Content Include="Web.Staging.config">
<DependentUpon>Web.config</DependentUpon>
<SubType>Designer</SubType>
</Content>
<Content Include="Web.Production.config">
<DependentUpon>Web.config</DependentUpon>
<SubType>Designer</SubType>
</Content>
Unfortunatelly I did not find a way to acomplish this through visual studio.

This is the third time I've set one of these up in a project and I get stuck every time. The key is that the config transform files are linked to the named build configurations.
If you go to Build > Configuration Manager... and select the Active solution configuration drop-down you can add new build names. Afterward you can right-click your web.config and Add Config Transform, which asks no questions and just creates one transform for each build.
Renaming an existing build didn't work, it still generated a transform with the original name, but you can delete builds or selectively delete the transform files.

If you are using the extension Configuration Transform go to Build > Configuration Manager and find the Configuration dropdown for the project of which you want to change the app config. You can then select the edit and rename the build configurations for that project. Then re-run the Configuration Transform tool and it will generate app configs using the names you provided in the build configuration settings.

What I found worked for me is to just delete the Debug and Release, and then create new ones. Saved me a lot of worry with dangling references and build errors and the like

Related

Azure sitesroot does not contain all deployed files

I'm deploying a web role to Azure using VS 2013. I added a Contents element to my .csdef file to deploy extra files that are not included in the Azure deployment package like this:
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="..." xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2014-06.2.4">
<WebRole name="..." vmsize="Small">
<!-- snip -->
<Contents>
<Content destination="bin/">
<SourceDirectory path="C:\...\bin"/>
</Content>
</Contents>
</WebRole>
</ServiceDefinition>
When the package is deployed, I can see the extra files being put in the approot folder on the instance's F: drive. However, these files are never deployed to the sitesroot\0 folder, from which the web role seems to run. Because these extra files are assemblies that are to be loaded dynamically, I would like them to be together with the application's other assemblies.
Is this behavior intentional or am I doing something wrong? There doesn't seem to be much information about this online.
I ended up using the Content element in the end, but with a different destination path, pointing to the sitesroot folder. It's a bit of a hack, but at least it works without diving into MSBuild or manual packaging of the deployment.
<ServiceDefinition name="..." xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2014-06.2.4">
<WebRole name="..." vmsize="Small">
<!-- snip -->
<Contents>
<Content destination="..\sitesroot\0\bin">
<SourceDirectory path="C:\...\bin" />
</Content>
</Contents>
</WebRole>
</ServiceDefinition>
The behaviour is as per the documentation which states that the deployed location is relative to the Role's APPROOT (the behaviour you are seeing).
If you want them deployed into your site's bin folder you need to package them as part of your Visual Studio solution.
You can add a DLL to your root directory of a project (Add -> Existing Item). If you take that DLL and change the Build Action set to Content and the Copy to Output Directory set to Copy Always then I think this will make sure that the DLL ends up being in your BIN folder, or equiv.
An example of what I've done in the past:
Two projects in a Solution named:
DependenciesProject (Class Library)
WebProject (MVC App)
I had a need where some specific DLLs that needed to be bundled into the compiled package were included but the specific DLL that would be used would change based on my compiled targets (x64 vs x86). The solution we chose to go with was to have the DependenciesProject do what I described for you to do above and we modified the .csproj file to change the path to these native DLLs based on the target specified at compile-time (we disabled Any CPU).
So the DependenciesProject had these DLLs in the root directory (with that .csproj having some tweaks for dynamic paths to the DLLs that existed in our Nuget packages folder) and the DLLs in the Solution Explorer had the Build Action set to Content and the Copy to Output Directory set to Copy Always. This means whenever a DependenciesProject.dll file was compiled, it would move the other DLLs into the same output folder as that .DLL file.
Now WebProject project would have a Project Reference to DependenciesProject. This means every time I try to compile WebProject, it will first compile DependenciesProject and then copy its output folder into the WebProject's output folder.
The end result: DependenciesProject.dll as well as MySpecial.dll existed with my web application every time I needed it.
Does this help?

What is the name of the web role .config file with SDK 2.2

I have a web role in which I have extended the RoleEntryPoint to do some work that is outside of the scope of the web site. As part of the RoleEntryPoint.Run() my code is required to read from the .config using ConfigurationManager.
While this is a little unusual, using SDK 1.8 I was able to make this work by ensuring that my package included a [The name of my project].dll.config file.
Now that I have upgraded to SDK 2.2 when I try to use .AppSettings or .GetSection() the values are always null, which leads me to believe it is unable to find my file.
I have tried deploying a Worker Role and the .config file still follows the same name pattern that I'm currently using.
I have also tried naming the file WaIISHost.exe.config.
I am aware that ideally this configuration should be included in the .csfg file, but my questions is does anyone know what I should be calling my config file?
UPDATE:
With the help of this question, I now know that the name of the config file it is reading from is E:\base\x64\WaIISHost.exe.Config, but I don't know why this has changed or what I can to overide this.
After much investigation and trial an error I finally have a solution.
The name of the file is still required to be [The name of my project].dll.config, but you need to make sure that this file is in your approot\bin\ directory of your package.
I believe my initial problem was caused by the Copy to Output Directory property being changed to Do Not Copy, although I'm unsure how this happened. If you find yourself in a similar situation you can just add a file with the correct name to your project and set the Copy to Output Directory to be Copy Always.
Once I'd done that however I realised I had another problem. I needed the .config file to have had the config transformations run over it, which this didn't do. To fix this I updated the .ccproj file to have the following:
<PropertyGroup>
<!-- The first two of these targets are what is defined in the base SDK 2.2 targets file. When we upgrade we may need to look reassess this. -->
<CopyRoleFilesDependsOn>
CopyWebRoleFiles;
CopyWorkerRoleFiles;
CopyWebConfigToBin;
</CopyRoleFilesDependsOn>
</PropertyGroup>
<Target Name="CopyWebConfigToBin">
<!-- We need to copy the transformed Web.config to the bin directory so that the RoleEntryPoint has access to the config settings.-->
<Message Text="Copy %(WebRoleReferences.OutputDir)Web.config tp %(WebRoleReferences.OutputDir)\bin\BackOffice.UI.dll.config" Importance="high" />
<Copy SourceFiles="%(WebRoleReferences.OutputDir)Web.config" DestinationFiles="%(WebRoleReferences.OutputDir)bin\[Name of project].dll.config" />
</Target>
This adds an extra target which waits until all of the other files have been copied to the appropriate directory and then picks up the web.config and puts a copy in the bin directory with the correct name.
Are you able to put the config values into the Azure config file (the .cscfg) rather than using the .config file? You can read the values from the cscfg via the RoleEnvironment.GetConfigurationSettingValue static method.
This page explained why it's called WaIISHost.exe.Config and where you can put it in your project.
http://azure.microsoft.com/blog/2010/12/02/new-full-iis-capabilities-differences-from-hosted-web-core/
Like knightpfhor mentioned, you can also use [AssemblyName].dll.config to put these configuration too. It depends on the assembly name of your project, you can check property of your web role project.

how to add files in web.config transformation process?

I am having a website developed in Visual Studio 2012.
The web.config is currently containing following files in its transformation:
- web.Debug.config
- web.Release.config
I have recently added a new build configuration (named as "Staging") in my project. How can I create a "web.Staging.config" transformation file?
There are two ways for the web.config transform files to be generated within VS:
If you have a web application project, Right-click on web.config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).
This method is not supported for Website projects as they do not support multiple build configurations.
In either web project type, right click on a publish profile (.pubxml) and choose Add Config Transform. This will add a new config transform for that profile only.
This requires VS2012 Update 2 or the Azure SDK 2.0 for VS2010 (I think).
In a web site project, the new transform file will not be nested under web.config as VS doesn't support that behavior. Just look for it in the root folder.
IN VS 2012:
Go to Build->Configuration Manager
Click on the Active solutions configuration and select "New".
Enter the name of your new configuration and click Save.
Right click on your Web.config file and select Add Config Transform.
Your new transform file will be automatically created.
You need to first install the Configure Transform extension [Extensions -> Manage Extensions -> Online section] to see the option when right-clicking your web.{environment}.config files.

AjaxMin not working on Azure site

I am using Microsoft's AjaxMin to minify javascript on my website, which is hosted by Azure. I am using a BuildTask to automatically minify javascript at run time. This build task is specified in the .csproj file.
The process is working on my local environment, however, it does not work when I deploy to my Azure site. The azure site throws 404: file not found errors, when i try to reference the minified version of .js files.
Is it possible to use build tasks on an Azure site? Is there anything I am missing? I have made sure not to include the .min.js files in source control as this (http://www.asp.net/ajaxlibrary/AjaxMinQuickStart.ashx) tutorial suggests, but I am wondering if there is anything specific to Azure that I need to set up.
Thanks!
I've got this working properly in my projects. I'll tell you how I did it, though this may not be the simplest or most straightforward way.
Before we get started, it's helpful to be able to check if your minified files are included in the Azure deployment package without actually deploying. It's pretty easy to do. The .cspkg file is actually a zip-formatted file, so you can open it with any zip archiver. (I like to use 7Zip for this because the right-click -> Open Archive command doesn't require you to rename the file, but you could use Windows Explorer, WinRAR, etc.) Inside the .cspkg you'll see another large file with a .cssx extension. That's a zip file too. Inside of the .cssx you'll find a sitesroot folder with a subdirectory for each website you're deploying, which will contain all your actual website files. So you can poke around in there and see what files are being deployed to Azure.
First, try editing the project file for your web project (the one that contains all the Javascript/CSS files). You can use Notepad, or in Visual Studio right-click the project, select "Unload Project", then right-click again and select "Edit ". Inside the project file, insert a section like this:
<ItemGroup>
<!-- Copy over all the minified CSS & JS to the output directory-->
<Content Include="**\*.min.css" />
<Content Include="**\*.min.js" />
</ItemGroup>
Then reload the project, repackage it, and see if your files are included in the .cspkg file. If they are, then you're done.
If not, there are a couple other things to check. Your minification might not be running at the right build stage. My minification target looks like this:
<Target Name="PrepWebApp" Condition="$(Configuration)=='Release'" AfterTargets="AfterBuild">
If that's still not working and your Web Role has multiple Sites and/or Virtual Applications in it, it's possible that the packaging steps are not running for all of the sites. So when you go to package your project for deployment to Azure, it may still not be running the minification step (along with the web.config transformations, and some other things). If that's the case, see this blog post for a way to fix it.
Just in case that blog post goes away, I'll copy the most relevant bit here. You would put this in the .ccproj file for your web role (with appropriate bits changed to match your project structure):
<PropertyGroup>
<!-- Inject the publication of "secondary" sites into the Windows Azure build/project packaging process. -->
<CoreBuildDependsOn>
CleanSecondarySites;
PublishSecondarySites;
$(CoreBuildDependsOn)
</CoreBuildDependsOn>
<!-- This is the directory within the web application project directory to which the project will be "published" for later packaging by the Azure project. -->
<SecondarySitePublishDir>azure.publish\</SecondarySitePublishDir>
</PropertyGroup>
<!-- These SecondarySite items represent the collection of sites (other than the web application associated with the role) that need special packaging. -->
<ItemGroup>
<SecondarySite Include="..\WebApplication1\WebApplication1.csproj" />
<SecondarySite Include="..\WebApplication2\WebApplication2.csproj" />
</ItemGroup>
<Target Name="CleanSecondarySites">
<RemoveDir Directories="%(SecondarySite.RootDir)%(Directory)$(SecondarySitePublishDir)" />
</Target>
<Target Name="PublishSecondarySites" Condition="'$(PackageForComputeEmulator)' == 'true'
Or '$(IsExecutingPublishTarget)' == 'true' ">
<!--
Execute the Build (and more importantly the _WPPCopyWebApplication) target to "publish" each secondary web application project.
Note the setting of the WebProjectOutputDir property; this is where the project will be published to be later picked up by CSPack.
-->
<MSBuild Projects="%(SecondarySite.Identity)" Targets="Build;_WPPCopyWebApplication" Properties="Configuration=$(Configuration);Platform=$(Platform);WebProjectOutputDir=$(SecondarySitePublishDir)" />
The build task will run in Visual Studio when you build the project. You need to make sure that the minified files are also being deployed to Azure.
I'm guessing that perhaps because the item is being generated at build-time that it's not part of the project itself, and is this ignored by the deployment step.
Please check that the deployment system being used will include all the script files and not just the ones that are in the project itself.

Can the default location of an Orchard CMS module be changed?

I'm setting up an Orchard CMS project with the intention of creating a module to house my MVC 3 application. This application has already been started and has 5 projects already. One web project, some test projects and a workflow project.
Requiring that the web project (and therefore the other 4 projects for simplicity) lives within /Orchard.Web/Modules/ is a minor inconvenience - is it possible to change where Orchard looks (or add a new location) when dynamically loading the modules?
It's not a massive deal, but a nice to have for this project.
In an ideal world i'd be able to have:
/OrchardStuff/Orchard.Web
/OrchardStuff/etc
/MyStuff/MyProj.Web
/MyStuff/MyProj.Tests
I know i can arrange my sln in a nice usable way, would be nice if i could replicate this in the file system.
Cheers.
Wouldn't be easier to add an afterBuild task in your web project to copy the application to the Orchard's modules directory?
Something like that in the csproj file would do the trick (sort of, I am not entirely sure of my syntax. :'( )
<Target Name="AfterBuild">
<ItemGroup>
<AppFiles Include="**\*.*"/>
</ItemGroup>
<Copy SourceFiles="#(AppFiles)"
DestinationFiles="#(AppFiles->'..\OrchardStuff\Orchard.Web\Modules\MyModule\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
The MSDN documentation is here: http://msdn.microsoft.com/en-us/library/3e54c37h.aspx
The solution I used is adding the following line to post-build operation:
if not exist "$(SolutionDir)..\Orchard\src\Orchard.Web\Modules\$(ProjectName)" mklink /D "$(SolutionDir)..\Orchard\src\Orchard.Web\Modules\$(ProjectName)" ""$(ProjectDir)"
This command creates a symlink of your dev folder inside Orchard's Modules folder (only if such symlink doesn't already exist).
It has the following advantages over #Eilistraee's answer:
If you change Javascript/CSS file in your dev machine, you don't need to build the project to get the changes into Orchard.
You don't get duplicate files on your drive
Post-build is a more explicit option and the macro variables make it easy to copy to any new module.
No that's not possible without some major efforts. Not worth it.

Resources