简体   繁体   中英

Powershell Include In Project From Package Manager Console In Visual Studio

How can I perform "Include In Project" as in Solution Explorer but by using Powershell from the Package Manager Console?

Say my solution looks like this:

- SolutionA
  - ProjectA
    - ...Some Folders And Files...
  - ProjectB
    - FolderA
    - FolderB
      - FileA
      - FileB (Excluded from project)

How can I include FileB in my solution?

Thanks in advance!

Every now and then, when I need to see how to automate Visual Studio from a PowerShell script, I have a look at existing NuGet packages. One of them is the SQL Server Compact embedded database. If you open the corresponding feed in NuGet Package Explorer , you'll see that it contains a module for automating VS called VS.psm1. That modules contains several useful functions, one of them allowing to do exactly what you want. Worth to have a look and see how it works.

I was able to use ProjectItems.AddFromFile to add the file into my project.

$myProject.ProjectItems.AddFromFile("PathOfFileOnDisk")

Where $myProject is a variable reference to the target project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM