Open file in visual studio via nuget manager console - visual-studio

context information
I Use the scaffolder nuget package to make database upgrade classes. by calling scaffold dbupgrade in the package manager console.
De upgrade powershell file ends with: Add-ProjectItemViaTemplate ....
What i want
It all works great and generates a class for me and adds it to the project file but: I would like to open the generated file in my solution.
Is this possible? and how would i go from here?
I use visual studio 2015 Community edition.
What I tried
I tried commands such as Open-File, Open-Document but these do not exist.

I found my solution on another stackoverflow question: https://stackoverflow.com/a/28426592/1275832
the solution would be:
$DTE.ExecuteCommand("File.OpenFile", "App.config")
For a nuget package Install.ps1 you could do:
param($installPath, $toolsPath, $package, $project)
//Get specific file
$file = $project.ProjectItems.Item("`$rootnamespace`$.nuspec")
//Get its location
$location = $proj.ProjectItems.Item("App.config").Properties['LocalPath'].Value
//Open the file in the IDE
$project.DTE.ExecuteCommand("File.OpenFile", $location)

Related

The specified deps.json [] does not exist

I'm using Asp.net Core with EntityFramework.Core. I'm having troubleshot migrations and Scaffold after format my pc.
when I write these in Package Manager Console
Scaffold-DbContext "Data Source=.\SQL2017DEV;Initial Catalog=MyDataBase;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Db
Add-Migration Initial
error is
"The specified deps.json [D:\TFS\Erdi\Erdi\AspCoreWeb.Site\AspCoreWeb.Site.deps.json] does not exist"
[MyProjectFolder]\AspCoreWeb.Site.deps.json
I think it try to find my debug folder.
This solutioun is working other computers
I'm repair my visual studio but it hasn't changed
In my case; was fixed by changing the Startup Project (via Solution Properties) to the project that has EF Context file.
There is an issue with migration in VS2019. I have been facing a similar issue and was getting below error:
The specified deps.json [YourProjectLocation]\ProjectName.deps.json doesn't exists.
When I used dotnet CLI for migrations and it worked and was able to generate migration and update the same using dotnet CLI.
dotnet ef migrations add InitialCreate
dotnet ef database update
this problem generally occurs because of path issues. You should change your "outputPath" in the "project.assets.json" file.
D:\TFS\Erdi\Erdi\AspCoreWeb.Site\AspCoreWeb.Site.deps.json] instead of this,
D:\TFS\Erdi\Erdi\AspCoreWeb.Site\obj\AspCoreWeb.Site.deps.json]
i think this will resolve your problem.
If you are using Package Manager Console to "Add-Migration" or "Update-Database", be sure that the project where you want the migration is selected as the Startup project in Visual Studio and this project is also the default in Package Manager Console.
Solution Explorer:
Package Manager Console:
If you are using the dotnet CLI, then you have to navigate to the right project folder and run the migration commands from there.
Make sure that the Startup Project is where the connection string is and select the project in the Default project of Package Manager Console where the db context is at.
Just Go to VS 2022
It Worked for me
go to bin folder and copy files in it include deps.json to the path that see in error.

Could not write destination file: Access to path 'd:\a\src\...\Web.config' is denied

I have a tfs project on visual studio online and created a build definition to compile this project. The project uses web config transformation. The build will be executed from the visual studio online hosted build controller and it fails because of the following error:
Could not write destination file: Access to path 'd:\a\src...\Web.config' is denied.
Any ideas how to resolve this issue?
Sounds like the classic problem of read-only files (see cannot modify .csproj files using build auto with tfs 13). Run a pre-build Powershell script that removes the attribute, something like this
Get-ChildItem -Include *.config -Recurse | foreach {
if ($_.IsReadOnly) { $_.IsReadOnly = $false }
}

How do I set Visual Studio to build a NuGet package?

How can I get Visual Studio to build a NuGet package for my library component on build?
I’m using a Portable Class Library as the example project.
Ensure the NuGet.exe file in .nuget folder is latest.
Default values come from AssemblyInfo.cs, so clean that up.
Add a NuGet package reference if you do not reference any, preferably something simple like JSON.NET. Often, PCL projects have no external dependencies, in which case no NuGet refs and without any NuGet refs, the required MSBuild config won't get set properly, so we need to add a 'dummy'.
Enable NuGet Package Restore.
Edit the NuGet.targets file and ensure BuildPackage is true.
<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">true</BuildPackage>
Edit your .csproj file and add this to the first, default PropertyGroup
<BuildPackage>true</BuildPackage>
Rebuild your project and then search in the Output for nupkg and confirm creation and location of the package file.
Remove the dummy NuGet package reference and build again and check the Output.
To further customize the package creation, you can stick a MyProjectName.nuspec file next to your .csproj file.
See http://docs.nuget.org/docs/reference/nuspec-reference for more on the NuSpec format. You can also pull one from an existing package (its just a zip file) and have a nose around, see how it was done.
Add a post-build event like this:
$(SolutionDir)\.nuget\nuget.exe pack "$(MSBuildProjectFullPath)" -p Configuration=Release -o "$(MSBuildProjectDirectory)\bin\Release" -symbols"
And download and place nuget.exe in the .nuget folder alongside your solution file.
You can use nuget update -self to keep the .exe fresh.
Note
nuget.exe pack has a bug currently where it'll see a packages.config file and try to look for the packages it mentions in your solution but it fails to find them if the packages folder is in a strange place, e.g. if your solution file isn't a level up from the project.
To workaround this, add another post build event to copy the packages folder into the project folder.
The repositorypath config setting seems to do nothing for me.
See GitHub reports:
https://github.com/NuGet/Home/issues/5316
So funny. I was having problems with my usual way of auto-building a package on build when I arrived at this new way. So I looked for a suitable SO question to answer with my new post-build method when I came across my own question here!

How to launch a web page after installation with Visual Studio Installer

I would like to launch an URL after the installer finishes. I added an *.url file to the project content and added the content files in the Visual Studio Installer project. Then I try to add the *.url in the Commit Custom Action putting the name of the file in the Name field, the EntryPoint says "Commit" and the InstallerClass in false.
When I compile the Visual Studio Installer project it game me an error that Entry point 'Commit' not found in module for custom action *.url
Is it possible to do this without adding an InstallerClass?
You can use a VB script file to run a shell command on the URL file. Look here

Modifying Visual Studio solution and project files with PowerShell

We are currently reorganizing our source code, moving stuff around in a new directory
structure. This impacts our Visual Studio solution and project files, where things like assembly references, possibly output directories, pre and post build events, and so on ... must be updated to reflect our changes.
Since we have many solutions and projects, my hope was to partly automate the process using PowerShell, with something like a PowerShell "provider" for VS:
In an ideal world, I would be able to do something like:
$MySolution.Projects["MyProject"].PostBuildEvent = "copy <this> to <that>"
I know about PowerConsole (which I haven't fully explored yet) for scripting Visual Studio. However, the documentation is scarce and I'm not sure it really covers my needs.
Anything else for easily manipulating solution and project files? Preferably in PowerShell, but I'm open to other suggestions.
In my experience, the easiest way to manipulate Visual Studio solutions using PowerShell (from within or outside of Visual Studio) is to load the project file as XML and use PowerShell to manipulate it.
$proj = [xml](get-content Path\To\MyProject.csproj)
$proj.GetElementsByTagName("PostBuildEvent") | foreach {
$_."#text" = 'echo "Hello, World!"'
}
$proj.Save("Path\To\MyProject.csproj")
If you're running your script in the NuGet Package Manager Console, you can get the paths to all of the project files like so:
PM> get-project -all | select -expand FileName
C:\Users\Me\Documents\Visual Studio 10\Projects\MyProject\MyProject.csproj
C:\Users\Me\Documents\Visual Studio 10\Projects\MyProject\MyProjectTests.csproj
PM>
Editing solution files from PowerShell is very picky about the characters you use in whitespace, making it a pain to automate with text replacements.
If you're editing VS Solution files with PowerShell, there's a good chance you've also got access to the dotnet CLI. I recommend invoking the dotnet CLI from PowerShell instead and using the built-in sln command:
Usage example:
# Create a solution, a console app, and two class libraries.
dotnet new sln -n mysolution
dotnet new console -o myapp
dotnet new classlib -o mylib1
dotnet new classlib -o mylib2
# Add the projects to the solution
# Use --solution-folder to organize the class libraries into a solution folder.
dotnet sln mysolution.sln add myapp\myapp.csproj
dotnet sln mysolution.sln add mylib1\mylib1.csproj --solution-folder mylibs
dotnet sln mysolution.sln add mylib2\mylib2.csproj --solution-folder mylibs
When invoked from PowerShell, you can even use Glob patterns:
dotnet sln todo.sln add (ls -r **/*.csproj)
Docs & examples:
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-sln

Resources