Brussells Development Blog

Tag: .net

VStudio Web.config Transformation for your App.configs

by on Jul.01, 2011, under Development, Tips and Tricks

I searched high and low for this tid-bit before finally stumbling upon this great question\answer over at Stack Overflow. I’m going to lay out the steps here for reference but credit goes to Oleg Sych and Dan Abramov.

Original article:
App.Config Transformation for projects which are not Web Projects in Visual Studio 2010?

 

1.) Add an XML file for each configuration to the project.

Let’s say your project build settings are Debug.Local, Debug.Production, Release.Local, Release.Production. Then your new app.config files should be titled as app.<build title>.config …. or app.Debug.Local.config, app.Debug.Production.config, etc. One file for each build configuration. Once they are added to your project continue to step 2.

 

2.) Unload project and open *.csproj file for editing

Right-click on the project and select Edit project file from the Solution Explorer.

 

3.) Bind app.configs created in Step 1 to original app.config

Find the section inside the project file that contains app.config and all the app.<build title>.config files you just manually added. Notice how their build actions are set to None.

  1. Set all the app config files build action to Content
  2. Make all the app config files you manually added dependent upon the original app.config file.

When you finished it should look something like this:

<Content Include="App.config" />
<Content Include="App.Debug.config" >
  <DependentUpon>App.config</DependentUpon>
</Content>
<Content Include="App.Release.config" >
  <DependentUpon>App.config</DependentUpon>
</Content>

 

4.) Activate transformation magic

In the end of the file after

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

and before final

</Project>

Insert the following XML:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
    <!-- Generate transformed app config in the intermediate directory -->
    <TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
    <!-- Force build process to use the transformed configuration file from now on. -->
    <ItemGroup>
      <AppConfigWithTargetPath Remove="app.config" />
      <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
        <TargetPath>$(TargetFileName).config</TargetPath>
      </AppConfigWithTargetPath>
    </ItemGroup>
  </Target>

Now you can reload the project. Make sure that all the manual app.<build settings>.config files you added earlier are now neatly tucked away under the original app.config file.

Build and enjoy!

 

Leave a Comment :, , , , more...

SFRS.com and ASP.NET 2.0 Security …

by on Jul.09, 2007, under Win32

Finally, after days of toying and learning how the new Authorization system in .NET 2.0 worked I managed to get it to work properly on my Win2k3 box for the production server. If you have ever worked with the new Authorization system in 2.0 .NET then you may already know the troubles you can run into.

I implement a MySQL 5.0 server system for all my websites currently so I needed to write my own Authorization systems to work with MySQL. The only ones supported out of the box was a MDF SQL Server file for use with MS SQL Server Express, MS SQL Server, Windows Auth, and I believe a Active Directory version. Once I implemented my own library for use with MySQL server + Authorization I implemented it on my latest version of the Sumiton Fire and Rescue site on my local Vista Dev box. Well of course it ran fine and worked fine on it. When the time came to do a push to my production server ( Windows Server 2003 box ) nothing worked. Go figure =/.

Over the next few days I managed to track down the problem, which was a silly one if you ask me. I ended up removing the System.Authorization tags and allowdeny tags from the main web.config file located in the main branch of the site, and creating a new web.config file inside the directories that needed security with just the allowdeny tags. After some forum reading, I managed to get the tags just right and BINGO !!! A new .NET 2.0 Authorization system that works fully with MySQL on the backend.

I still can’t see why putting the allowdeny tags in the main config file worked on dev box, yet borked on production. Microsoft, I swear they love messing with us developers sometimes. =/

-Brandon
One Tired Dev Monkey

Leave a Comment :, more...

Web Server Fun

by on Jun.21, 2007, under Win32

Today I managed to get some small tasks ( yet important ones ) taken care of. In preparations for moving Sumiton Fire and Rescue over to this dedicated box, I finally got my email server installed and properly configured. The longest part was probably configuring the Webmail portion of the server. My IIS and ASP.Net 2.0 didn’t go over well with this slightly older version of email server software, which wanted ASP.Net 1.1.

After some tweaking, and old school manipulation ;p … I got it to finally take. Now I have a email server with good Spam blockage, Virus Scanning, and a versatile Webmail site that can easily attach to those sites I wish to give email functionality to.

So far so good, just one step closer to moving over the Fire Dept. site. Although, the major things left still lie with me finishing up the ASP.Net 2.0 coding I have left to do. This will be the 3rd major over haul for the site within a 5 year span. Not too aweful bad, considering it’s staying on the cutting edge of what software and servers have to offer.

Leave a Comment :, more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...