© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
25 replies
no >> body

✅ Iteration through a list in csproj

I have a csproj file with a next section

  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish" Condition="'$(BuildingDocker)' == ''">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec WorkingDirectory="$(SpaRoot)" Command="yarn install" />

    <!-- Iterate over each environment in the Environments variable and run yarn run build:<ENVIRONMENT> -->
    <ItemGroup>
      <Environment Include="$(Environments)" />
    </ItemGroup>
    <Message Importance="high" Text="Started building %(Environment.Identity) versions of the spa ..." />
    <Exec WorkingDirectory="$(SpaRoot)" Command="yarn run build:%(Environment.Identity)" />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)%(Environment.Identity)\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>
  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish" Condition="'$(BuildingDocker)' == ''">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec WorkingDirectory="$(SpaRoot)" Command="yarn install" />

    <!-- Iterate over each environment in the Environments variable and run yarn run build:<ENVIRONMENT> -->
    <ItemGroup>
      <Environment Include="$(Environments)" />
    </ItemGroup>
    <Message Importance="high" Text="Started building %(Environment.Identity) versions of the spa ..." />
    <Exec WorkingDirectory="$(SpaRoot)" Command="yarn run build:%(Environment.Identity)" />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)%(Environment.Identity)\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

This is how I pass environments
dotnet publish --configuration Release -p:Environments=sandbox;dev;qa;staging
dotnet publish --configuration Release -p:Environments=sandbox;dev;qa;staging


It works correctly only for the first value from environments.
On the second iteration it shows me an error
dev: The term 'dev' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
qa: The term 'qa' is not recognized as a name of a cmdlet, function, script file, or executable program.
.....
dev: The term 'dev' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
qa: The term 'qa' is not recognized as a name of a cmdlet, function, script file, or executable program.
.....

I'm wondering how to make it work for the rest of the environments?

My package.json file contains all env-specific commands
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

✅ Iterate through a genereic type list
C#CC# / help
3y ago
Copy folder in .csproj
C#CC# / help
3y ago
Identifying the Framework in a .csproj file
C#CC# / help
2y ago
✅ Local csproj
C#CC# / help
11mo ago