I'm working on one OSS project that uses nuget to distribute its packages.
Today I encountered a problem that some projects are fine when you reference them directly, but they don't restore from nuget because of weird versioning errors.
So I'd like to prevent unusable code from being merged into master branch.
I removed all local references, and created following pre-build event:
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command=""$(MSBuildBinPath)\msbuild.exe" /t:pack "$(SolutionDir)CodeGeneration.Roslyn/CodeGeneration.Roslyn.csproj"" />
<Exec Command=""$(MSBuildBinPath)\msbuild.exe" /t:pack "$(SolutionDir)CodeGeneration.Roslyn.Attributes/CodeGeneration.Roslyn.Attributes.csproj"" />
<Exec Command=""$(MSBuildBinPath)\msbuild.exe" /t:pack "$(SolutionDir)CodeGeneration.Roslyn.Tasks/CodeGeneration.Roslyn.Tasks.csproj"" />
<Exec Command=""$(MSBuildBinPath)\msbuild.exe" /t:pack "$(SolutionDir)CodeGeneration.Roslyn.Tool/CodeGeneration.Roslyn.Tool.csproj"" />
</Target>
Okay, now it packs all required projects. Then I want to reference them. Now my pre-build looks like:
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command=""$(MSBuildBinPath)\msbuild.exe" /t:pack "$(SolutionDir)CodeGeneration.Roslyn/CodeGeneration.Roslyn.csproj"" />
<Exec Command=""$(MSBuildBinPath)\msbuild.exe" /t:pack "$(SolutionDir)CodeGeneration.Roslyn.Attributes/CodeGeneration.Roslyn.Attributes.csproj"" />
<Exec Command=""$(MSBuildBinPath)\msbuild.exe" /t:pack "$(SolutionDir)CodeGeneration.Roslyn.Tasks/CodeGeneration.Roslyn.Tasks.csproj"" />
<Exec Command=""$(MSBuildBinPath)\msbuild.exe" /t:pack "$(SolutionDir)CodeGeneration.Roslyn.Tool/CodeGeneration.Roslyn.Tool.csproj"" />
<Exec Command="Install-Package CodeGeneration.Attributes -Source "$(SolutionDir)../bin/Packages/$(Configuration)"" />
<Exec Command="Install-Package CodeGeneration.Tasks -Source "$(SolutionDir)../bin/Packages/Packages/$(Configuration)"" />
<Exec Command="Install-Package CodeGeneration.Roslyn -Source "$(SolutionDir)../bin/Packages/Packages/$(Configuration)"" />
<Exec Command="Install-Package dotnet-codegen -Source "$(SolutionDir)../bin/Packages/Packages/$(Configuration)"" />
</Target>
But it doesn't work because of:
Install-Package : No match was found for the specified search criteria and package name 'CodeGeneration.Attributes'. Tr y Get-PackageSource to see all available registered package sources. At line:1 char:1 + Install-Package CodeGeneration.Attributes -Source C:\Users\Alex\Sourc ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex ception + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
It seems that it doesn't like prerelease packages (they look like CodeGeneration.Roslyn.0.4.38-gfe7ce5be9d.nupkg
), okay, checking for documentation and trying to add -IncludePrerelease
flag, but it doesn't work too:
Install-Package : A parameter cannot be found that matches parameter name 'IncludePrerelease'. At line:1 char:126 + ... os\CodeGeneration.Roslyn\src../bin/Packages/Debug -IncludePrerelease + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Install-Package], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
How could it be done? Maybe there is another approach which is way simpler and better? I have described it so detailed because I don't want fall into X-Y pitfall.