0
Follow
4
View

# Importing macros of a .csproj to a Directory.build.targets file?

dxh8678 注册会员
2023-01-26 04:52

Yes, that works. The `Directory.build.props` and `Directory.build.targets` files are evaluated respectively executed for each project separately. For each project, the corresponding macros (such as `\$(TargetPath)` or `\$(ProjectPath)`) will have the values for that particular project. So your above example `<BinaryFormats Include="\$(TargetDir)\$(TargetName).pdb"/>` should just work as written.

With additional conditions, you can also use these files to conditionally extend your projects. For instance, I have a large solution (100+ projects) where the `Directory.build.props` contains this section:

``````

``````

This automatically adds these two packages as references to all unit test projects (and only these), which not only reduces clutter on the project files themselves but also allows me to upgrade these packages with only changing a single line of code.

xianyuxuyang 注册会员

Publish Time
2023-01-26 04:52
Update Time
2023-01-26 04:52