PowerShell command to extract `<ProjectReference Include=(…)` from all `.csproj` files in a directory and its subdirectories

Get list of .csproj in directory and subdirectories of D:reposMTest

[1] PS D:reposMTest> ls -r -filter "*.csproj" | select Directory, Name

Sample output

Directory                       Name
---------                       ----
D:reposMTestM.Common        M.Common.csproj
D:reposMTestM.Mocks         M.Mocks.csproj
D:reposMTestM.StateMachines M.StateMachines.csproj

Get list of files containing line(s) that match <ProjectReferences*Include="([^"]+)" in directory and subdirectory

[2] PS D:reposMTest> ls | sls '<ProjectReferences*Include="([^"]+)"' | ForEach-Object {New-Object PSObject -Property @{Project=$_.Filename; DirectDep=$_.Matches.Groups[1].Value}}

Sample output

Project                DirectDeps
-------                ----------
dirs.proj              D:reposMTestM.Common
dirs.proj              D:reposMTestM.Mocks.csproj
dirs.proj              D:reposMTestM.StateMachines.csproj
M.Common.csproj        D:reposSCommonCommon.csproj
M.Common.csproj        D:reposQContractsContracts.csproj
M.Mocks.csproj         D:reposSControllerController.csproj
M.StateMachines.csproj D:reposMCommonCommon.csproj
M.StateMachines.csproj D:reposTAuthAuth.csproj

Questions

Q1: How can I feed the output of [1] to [2] to limit [2]’s search to .csproj files (i.e. exclude dirs.proj) to get the following output

Project                DirectDeps
-------                ----------
M.Common.csproj        D:reposSCommonCommon.csproj
M.Common.csproj        D:reposQContractsContracts.csproj
M.Mocks.csproj         D:reposSControllerController.csproj
M.StateMachines.csproj D:reposMCommonCommon.csproj
M.StateMachines.csproj D:reposTAuthAuth.csproj

Q2: And then how can I take that and make it group by Project/Filename? To get the following output (or similar)

M.Common.csproj, D:reposSCommonCommon.csproj, D:reposQContractsContracts.csproj
M.Mocks.csproj, D:reposSControllerController.csproj
M.StateMachines.csproj, D:reposMCommonCommon.csproj, D:reposTAuthAuth.csproj

Attempts

Attempts @ Q1

  • ls -r -filter "*.csproj" | ForEach-Object {"$_.Directory$_.Name"}
  • ls -r -filter "*.csrpoj" | select Path

Attempts @ Q2

  • ls | sls '<ProjectReferences*Include="([^"]+)"' | ForEach-Object {New-Object PSObject -Property @{Project=$_.Filename; DirectDep=$_.Matches.Groups[1].Value}} | group Project
  • ls | sls '<ProjectReferences*Include="([^"]+)"' | ForEach-Object {New-Object PSObject -Property @{Project=$_.Filename; DirectDep=$_.Matches.Groups[1].Value}} | group Project | select Name, Group
  • ls | sls '<ProjectReferences*Include="([^"]+)"' | ForEach-Object {New-Object PSObject -Property @{Project=$_.Filename; DirectDep=$_.Matches.Groups[1].Value}} | group Project | select Name, Group.DirectDep

The second of the 3 has the closet output to what I’m looking for

Name                   Group
----                   -----
dirs.proj              {@{Project=dirs.proj; DirectDep=...M.Common.csproj}, {Project=dirs.proj; DirectDep=...M.Mocks.csproj}, {Project=dirs.proj; DirectDep=...M.StateMachines.csproj}
M.Common.csproj        {@{Project=M.Common.csproj; DirectDep=...Common.csproj}, {Project=M.Common.csproj; DirectDep=...Contracts.csproj}}
M.Mocks.csproj         {@{Project=M.Mocks.csproj; DirectDep=...Controller.csproj}
M.StateMachines.csproj {@{Project=M.StateMachines.csproj; DirectDep=...Common.csproj}, {Project=M.StateMachines.csproj; DirectDep=...Auth.csproj}}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật