3

In my Parameters.xml file, I have a couple of parameters that use the Web Deploy "variable" syntax to refer to other parameters, like this one that refers to the IIS Web Application Name parameter:

<parameter name="MyParam"
           defaultValue="{IIS Web Application Name}/Web.config"
           tags="Hidden"/>

My problem is that VS automatically imports this parameter into my SetParameters.xml file when I build the deployment package in spite of it being tagged as hidden. When it is passed to msdeploy via setParamFile, Web Deploy literally interprets the value of the parameter as

{IIS Web Application Name}/Web.config

rather than substituting the IIS application name.

If I remove the parameter from the auto-generated SetParameters.xml file, the variable works as expected. Is there any way to prevent VS from including that parameter in the first place, either by name or by tag?

ladenedge
  • 13,197
  • 11
  • 60
  • 117
  • Can you explain why you are actually wanting to include the {IIS Web Application Name} macro, so we can look for an alternative? – kroonwijk Oct 06 '11 at 20:37
  • 1
    `MyParam` is used as an argument to the *setAcl* provider - we use it to make Web.config (and a couple of other files) writable for our deployment-time configuration tool. An [earlier question of mine](http://stackoverflow.com/questions/6861990/can-web-deploys-setacl-provider-be-used-on-a-sub-directory) might help explain exactly why the IIS application name is necessary. – ladenedge Oct 06 '11 at 23:26

2 Answers2

1

This was actually far easier than I thought, given the answer to my earlier question.

I just needed to add a Hidden tag in the target that follows AddIisAndContentDeclareParametersItems. This apparently sets the tag in the source manifest prior to the package being built. It ends up looking something like this:

<Target Name="DeclareCustomParameters" 
        AfterTargets="AddIisAndContentDeclareParametersItems">
  <ItemGroup>
    <MsDeployDeclareParameters Include="Foo">
      <!-- <snip> -->
      <!-- the following elements are the important ones: -->
      <Tags>Hidden</Tags>  
      <ExcludeFromSetParameter>True</ExcludeFromSetParameter>
    </MsDeployDeclareParameters>
  </ItemGroup>
</Target>

That was it!

Community
  • 1
  • 1
ladenedge
  • 13,197
  • 11
  • 60
  • 117
  • 3
    Doh! Wish you hadn't snipped the bit I was interested in! Am trying to declare a "variable" to use in other params using the MsDeployDeclareParameters syntax.... – Peter McEvoy Dec 08 '11 at 12:12
  • @PeterMcEvoy: The missing bit matches almost exactly a snippet on [Sayed's blog](http://sedodream.com/CommentView,guid,3d4f59f9-55bf-4b7b-809f-da6ef4774f4c.aspx). In my case, the `DefaultValue` is `{IIS Web Application Name}/Web.config`, and of course I match on "Web.config" rather than "Elmah". – ladenedge Dec 08 '11 at 13:44
  • 3
    if you still have it, it would be useful (for me and I'm sure others) to put the complete example of how to achieve this. – Martin Jul 26 '13 at 11:01
  • For what it is worth late in the game. I was just able to include ExcludeFromSetParameter="True" in my parameters.xml file and it worked like a champ. Maybe something has changed? – user2839499 Aug 01 '19 at 20:14
0

This answer is for anyone else looking for a more complete example of substitution via targets. This example shows substituting a variable "database server name" into a connection string.

The ExcludeFromSetParameter element appears to be the key to making substitution work as it keeps the param out of the SetParameters.xml file (as the OP mentioned he did manually). Unfortunately, I don't think that ExcludeFromSetParameter can be set from a parameters.xml file, so this is the only option...

<Target Name="DeclareCustomParameters" BeforeTargets="Package">
    <ItemGroup>

        <MsDeployDeclareParameters Include="DatabaseServer">
            <Description>Location of the database server hosting the user database</Description>
            <Value>localhost</Value>
            <DefaultValue>localhost</DefaultValue>
            <Tags>DBServer, SQL</Tags>
        </MsDeployDeclareParameters>    

        <MsDeployDeclareParameters Include="DB Connection String">
            <Kind>XmlFile</Kind>
            <Scope>Web.config</Scope>
            <Match>/configuration/connectionStrings/add[@name='Database']/@connectionString</Match>
            <Description>The connection string to the Database</Description>
            <DefaultValue>Data Source={DatabaseServer};Initial Catalog=MyDatabase;Integrated Security=true;MultipleActiveResultSets=true;</DefaultValue>
            <Tags>Hidden</Tags>
            <ExcludeFromSetParameter>True</ExcludeFromSetParameter>
        </MsDeployDeclareParameters>

    </ItemGroup>
</Target>
Rob Davis
  • 1,299
  • 1
  • 10
  • 22