-
I'm in a situation where I need to process on a project-by-project basis, and I've encountered a scenario where I have a project set to NOT be built via the Solution configuration for both Debug & Release. Usually, I point the dotnet cli to the Solution and allow it to handle these types of matters, but in this case that doesn't work for unrelated reasons. So now as I iterate over the projects, I need to skip any that are not supposed to be getting built. I've tried inspecting the Solution & Project objects (Nuke's own) and then for the Project's I've been peeking into the MSBuild project's properties trying to find something I could inspect there. I thought I had it when I found one called "Building" but that seems to always be false at the time I'm inspecting it. When I look at the Configurations property on both the Nuke Solution & Project objects, that's just a string value saying that the configuration is defined - but no further metadata is present. Any suggestions on a good way to implement a simple "IsBuildEnabledForConfiguration(string config)" type of helper method? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
I was focusing on inspecting all the Properties and failed to notice there is a true standalone property on the MSBuild Project object/type itself - IsBuildEnabled. I was expecting it to be part of the 'evaluated properties' so I kept focusing there. Now the bad part - it doesn't seem to have the correct value. I've got 2 different projects set to not be enabled via the Solution for both configurations and I am passing in the Configuration value when I get the MSBuild project type from the Nuke project type. Wondering if this is perhaps a bug; I'll peek at the source and see if I can find how it's getting the value but if this is coming from MSBuild itself and those native types and not Nuke I'm not sure why it wouldn't reflect the correct value. |
Beta Was this translation helpful? Give feedback.
-
After peeking at the source code for Nuke, I was looking at the ProjectModelTasks and the ParseProject doesn't seem to include awareness of the Solution and therefore its configurations for each project (this was a very quick glance only, so maybe I'm just not seeing how it does that). I'm thinking this may be a true bug in the sense that it wouldn't be accurate and something you could rely on. |
Beta Was this translation helpful? Give feedback.
-
Build configurations are part of the What you need to do is put |
Beta Was this translation helpful? Give feedback.
-
Digging in and refreshing my own memory on what the SLN file contains, I think I see something I can inspect and come to the correct conclusion - but - it still seems like the available property (IsBuildEnabled) should have worked and perhaps it should be based on the same logic I'm looking to leverage in the interim. What I see is in my SLN looks like the following: -- Project that is configured to build: -- Project that is NOT configured to build: So, it appears that I could test for the presence or lack of for the configuration that includes the ".Build.0" suffix and when it's not present that means it's not to be built. I'm going to attempt to use an interim version based on the code below:
|
Beta Was this translation helpful? Give feedback.
-
@matkoch thanks for the info; It does seem like the Project object has this awareness (somehow) since I could see the Configurations there and they do appear to be abiding by the Solution's configs. We are starting with the Solution object and then using a foreach(...) against Solution.Projects so that must somehow be making it work - for those that are built there's 4 items in the set versus the projects not set to be built only have 2. |
Beta Was this translation helpful? Give feedback.
Build configurations are part of the
Solution
model. A project loaded through theMicrosoft.Build
package has no awareness of whether it's enabled for build or not in the solution it's included in.What you need to do is put
Solution.Configurations
andProject.Configurations
together, but there's no built-in functionality.