question

TeaganStrauss-4555 avatar image
0 Votes"
TeaganStrauss-4555 asked ·

Trying to use msbuild to modify web.config and write to a new file, command succeeds but does nothing

I'm trying to write a PowerShell script to run on Atlassian Bamboo that calls msbuild to modify a web.config file based on a web.Beta.config file and write the results to a new web.Beta.config file in a new directory.
The msbuild command runs 'successfully', with 0 warnings and 0 errors in the build, but does not create anything.
The command I'm running is:
& 'Path To MsBuild\MSBuild' 'Path to Sln\MySln.sln' '/property:TransformInputFile=`"Path to Sln\Web\Web.config`";TransformFile=`"Path to Sln\Web\Web.Beta.config`";TransformOutputFile=`"Path to Sln\Publish\web.configs\Web.Beta.config`"'

vs-msbuild
· 7
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @TeaganStrauss-4555 , may I ask, did you follow or refer to some documents(or threads) to write the command? And did you change or customize some codes in .xxproj file and other related files?

0 Votes 0 ·

@TianyuSun-MSFT

did you follow or refer to some documents(or threads) to write the command?

Yes, this.

And did you change or customize some codes in .xxproj file and other related files?

I didn't change any csproj files directly, no. What I've done is:

1. Use ConfigurationManager in Visual Studio to add Beta, Dev and Prod builds
2. Modify web.Beta.config, web.Dev.config and web.Prod.config like below.
3. Run the command
0 Votes 0 ·
<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <location>
    <system.webServer>
      <aspNetCore>
        <environmentVariables xdt:Transform="InsertIfMissing">
          <environmentVariable name="Environment"
                               value="Beta"
                               xdt:Locator="Match(name)"
                               xdt:Transform="InsertIfMissing" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>


0 Votes 0 ·

Realized a problem. I'd forgotten the "/target:Transform".
Problem is now, it's failing with "error MSB4057: The target "Transform" does not exist in the project.".

0 Votes 0 ·
TianyuSun-MSFT avatar image TianyuSun-MSFT TeaganStrauss-4555 ·

Hi @TeaganStrauss-4555 , for this error, you need to add the target:Transform to the .csproj file. There isn’t a default target named Transform so you need to custom one for your project. You can refer to this thread.


0 Votes 0 ·
Show more comments

0 Answers