Loading a .NET project with items included as wildcards

Viewed 95

I've worked out that in my C#/F# code I can load information about any .NET project using

collection.LoadProject(path_to_my_proj_file)

where collection is of type ProjectCollection. I can then get the access to all the properties and items defined in the project and all of its dependencies. As an example I can get an access to all the files included via Compile in the following way

project.GetItems "Compile"

Let's assume I want to define a custom ItemGroup in my fsproj file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 ...
  <ItemGroup>
    <MyGroup Include="Test.txt" />
    <MyGroup Include="TestFiles\**\*" />
  </ItemGroup>
</Project>

Some comments:

  • MyGroup is my custom collection identifier. I've found out things like this are allowed
  • The "TestFiles" folder contains 4 files all together that exist in some subfolders, but they all match the pattern "TestFiles\**\*"

When I load the project using the method I had mentioned at the beginning and run

project.GetItems "MyGroup"

I get only one item, that is "Test.txt". The other files don't get discovered, unless I define them explicitly (i.e. without the wildcard) in the fsproj.

Is there a way for me to discover the files included using wildcards as well ? I'm even happy to get them in the unresolved form. So getting "TestFiles\**\*" instead of specific files that match the pattern is fine as well.

1 Answers

Found the solution.

First, let me say that the problem was on my side. In fact in general when you try to load a project, it DOES load also all the files. Even those defined with a wildcard, as long as the ofc match the pattern.

And here's the deal: in my application I don't use the plain collection.LoadProject, but rather a more sophisticated library. And yes - the library does some magic stuff that caused the problem.

In this situation the problem was simple: all the *.[cs|fs]proj files were copied to C:\temp\<random_folder_name>. Only *.[cs|fs]proj files - nothing less, nothing more. As a result, when the project loader attempted to evaluate the solution, there were simply no files to pattern-match, resulting in zero elements.

The lesson here is: writing a proper MCVE is important - would save me (and probably you as well) some time. Apologies for problems, guys!

Related