tag:help.appveyor.com,2012-11-13:/discussions/problems/6816-having-problem-setting-environment-variables-in-appveyor-with-powershellAppVeyor: Discussion 2018-10-19T08:18:22Ztag:help.appveyor.com,2012-11-13:Comment/427314712017-06-08T16:54:29Z2017-06-08T16:54:29ZHaving problem setting environment variables in appveyor with powershell<div><p>We'll fix that in the update coming this week.</p>
<p>For now, explicitly load AppVeyor module with:</p>
<pre>
<code>import-module 'C:\Program Files\AppVeyor\BuildAgent\Modules\build-worker-api'</code>
</pre></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/427314712017-06-08T18:06:27Z2017-06-08T18:06:27ZHaving problem setting environment variables in appveyor with powershell<div><p>Great, this worked for me. Thank you very much!!!</p></div>yosbeleg89tag:help.appveyor.com,2012-11-13:Comment/427314712017-06-08T20:12:50Z2017-06-08T20:12:50ZHaving problem setting environment variables in appveyor with powershell<div><p>Hmm, I have a question: When I set the configuration throw powershell msbuild is building the project with the Testing build configuration but it is applying the Debug transformation to the web.config, but if I set <code>configuration: Testing</code> to appveyor.yml everything is working as expected. Any ideas?</p></div>yosbeleg89tag:help.appveyor.com,2012-11-13:Comment/427314712017-06-08T20:35:04Z2017-06-08T20:35:04ZHaving problem setting environment variables in appveyor with powershell<div><p>If I understand you correctly, you have <code>publish_wap: true</code> in your YAML and transformation in generated WAP package does not respect <code>configuration</code> environment variable you set? I afraid this is how our WAP packaging implemented now, it looks only for project build configuration when constructing <code>msbuild</code> command. Could you please explain your scenario and why you need to set configuration using environment variable? We will try to find workaround for you.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/427314712017-06-08T20:50:48Z2017-06-08T20:50:48ZHaving problem setting environment variables in appveyor with powershell<div><p>Yes, I have <code>publish_wap: true</code> in the YAML, the transformation does not respect the configuration environment. I have an script the decides where it should build production or testing configurations before deploying to the production or testing servers depending if the commit is from master or a specific branch, very similar to the example of the original issue:<br></p>
<pre>
<code>Import-Module 'C:\Program Files\AppVeyor\BuildAgent\Modules\build-worker-api'<br><br>
<br>$branch = $env:APPVEYOR_REPO_BRANCH<br><br>
<br>function conf
{
param($config)
Set-AppveyorBuildVariable "configuration" $config
}<br><br>
<br>echo "... env:APPVEYOR_REPO_BRANCH: $branch"<br><br>
<br>if($branch -eq "testing-branch"){
conf "Testing"
}
else{
conf "Release"
}</code>
</pre>
<p>So, if it is the <code>testing-branch</code> the Testing configuration is set and the project is built with the Testing build configuration but the Web.Testing.config transformation is not applied instead the Web.Debug.config one is applied.</p></div>yosbeleg89tag:help.appveyor.com,2012-11-13:Comment/427314712017-06-08T20:52:53Z2017-06-08T20:52:53ZHaving problem setting environment variables in appveyor with powershell<div><p>May be you can simple use <a href="https://www.appveyor.com/docs/branches/#conditional-build-configuration">per branch configuration</a>?</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/427314712017-06-08T21:47:06Z2017-06-08T21:47:06ZHaving problem setting environment variables in appveyor with powershell<div><p>Ok, it took me a while to achieve the whole transformation but I think I did now per branch configuration and it seems to be working. Thanks again for the help!.</p></div>yosbeleg89tag:help.appveyor.com,2012-11-13:Comment/427314712017-06-08T21:51:12Z2017-06-08T21:51:12ZHaving problem setting environment variables in appveyor with powershell<div><p>The only think I did not liked is that I needed to put a lot a duplicated configurations per branch, is there a way to put all that only once?</p></div>yosbeleg89tag:help.appveyor.com,2012-11-13:Comment/427314712017-06-08T23:42:25Z2017-06-08T23:42:25ZHaving problem setting environment variables in appveyor with powershell<div><p>Agree, we don't like this too. We have <a href="https://github.com/appveyor/ci/issues/325">this feature request</a> which we need to implement.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/427314712017-06-09T14:12:50Z2017-06-09T14:12:50ZHaving problem setting environment variables in appveyor with powershell<div><p>Great!, Thanks</p></div>yosbeleg89