Build/Test Issues

Using environment variables in additional files to include path

Started by andcoll on 5,829 views

Hi,

Is it possible to use environment variables in the paths of files we specify in the "additional files to include" setting? When I try use them through the UI it complains that paths must be relative, and when I try add them to the .ncrunchproject file it doesn't seem to resolve them.

Relative paths are liable to break when we move things about.

Hi,

Thanks for posting!

There was some effort made to implement this, but it proved to be much more complicated than expected due to certain edge cases (such as absolute paths, which aren't allowed in this setting).

What do you need the environment variable for? Are you trying to work around a limitation?
Remco wrote:Hi,

Thanks for posting!

There was some effort made to implement this, but it proved to be much more complicated than expected due to certain edge cases (such as absolute paths, which aren't allowed in this setting).

What do you need the environment variable for? Are you trying to work around a limitation?


we have files that we need to include in the root of our repository, we've got a $(SRCROOT) env variable that points to this. So instead of ..\..\..\..\..\..\includedfile.xyz we'd prefer $(SRCROOT)\includedfile.xyz.

We've had issues where we've had to change a lot of ncrunchproject files after refactoring as the relative paths are now different.

We use these same env variables in our csproj files, it would be great if we could use them for ncrunch too.
andcoll wrote:
we have files that we need to include in the root of our repository, we've got a $(SRCROOT) env variable that points to this. So instead of ..\..\..\..\..\..\includedfile.xyz we'd prefer $(SRCROOT)\includedfile.xyz.

We've had issues where we've had to change a lot of ncrunchproject files after refactoring as the relative paths are now different.

We use these same env variables in our csproj files, it would be great if we could use them for ncrunch too.


Understood. At the moment NCrunch can't handle such a scenario with this setting, but it should be possible to use MSBuild instead.

MSBuild does work with environment variables, and NCrunch uses MSBuild to establish files it needs to include. It is possible to use this as an alternative to the Additional files to include setting.

For example, including the following in your project file should work:

<ItemGroup Condition="'$(NCrunch)' == '1'">
<None Include="$(SRCROOT)\includedfile.xyz" />
<None Include="$(SRCROOT)\IncludedDir\*.*" />
</ItemGroup>

I don't believe it's possible to include an entire directory tree using a single expression in MSBuild (others may correct me if there is a way to do this), so there may be some limitations with this approach.

Post a reply

Log in to reply.