As an example - I would like a Program.cs
file with a few default lines added to it:
class Program
{
// ...
}
This Program.cs
is in a C# project that I pack
and upload to DevOps artifacts.
I want to then go to install this package into a new 'console project' and have that project get its Program.cs
overwritten by my nuget package version.
This used to be possible in the .NET Framework, but in a .NET Core project, I am struggling to make it work.
How do you go about doing the above?
CodePudding user response:
You could use an init.ps1
, which is only run by Visual Studio (no other IDEs and definitely not when manually modifying .csproj files) upon installation and when opening the Package Manager (so your script can and will run multiple times).
NuGet in modern Visual Studio versions and projects uses <PackageReference>
, which only supports adding assembly references and read-only content files.
Scripting is brittle, and you should instead rely on documentation instead of modifying user files.
See also: