Specify Machine Name in Web.Config Transform
Asked Answered
W

2

8

I am using Web.config transforms to successfully create debug and release versions of the my web.config - this is working correctly.

I am interested to know whether there is a 'machine name' property to specify the current machine name which I can use in a debug URL, rather than hard-coding a specific machine name (using localhost isn't an option in the case), e.g.

<add name="XrmService" connectionString="http://$(ComputerName):5555/Service.svc" />

Are there any properties available using Web.config transforms? Similar to MSBuild's $(ComputerName) property?

Woald answered 12/8, 2013 at 15:0 Comment(0)
S
4

I faced a similar issue, what I ended up doing is :

1) Added the following build target to the project file. (Which is an MSBuild script effectively)

<Target Name="AfterBuild">
     <TransformXml Source="Web.config" Condition="Exists('Web.$(Computername).config') " Transform="Web.$(Computername).config" Destination="Web.config" />
</Target>

2) Added a Web.MyMachineName.config config transform file to the project. In your case it should look like this:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
        <add name="XrmService"
             connectionString="http://MyMachineName:5555/Service.svc"
             xdt:Transform="SetAttributes"
             xdt:Locator="Match(name)"/>
    </connectionStrings>
</configuration>

This has the benefit of running different transformations based on the machine name, without creating a separate build configuration. You can configure it to be debug only by specifying Condition="'$(Configuration)' == 'Debug'".

Streamer answered 1/8, 2016 at 11:35 Comment(0)
R
1

There is an Environment Variable that you can use. It is $(COMPUTERNAME).

Open a command window, type "set" (without the double quotes) and press Enter. You will see this Environment Variable somewhere at the top of the screen.

Rope answered 25/2, 2016 at 16:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.