Please I have a problem. sorry if question title are not recognized well, I can't upload full-image during my reputations.
Edit: I need something like that maybe
<ProjectReference>
should load and should become visible at my solution.Problem Short Description:
- I have main project in solution A. (Must be GIT public for other people)
- I have class library in solution B (Which maybe used in 2 main projects) (Must be GIT private repo for me only)
- I need the class library source only visible for me not other people. they just see Package or DLL.
- The main project are public Git repo, while class library are private Git repo.
- In my case I need to setup a 2 types of MSBuild configuration. (Debug/) and (Nuget/ )
- the other people only allowed to use which are private nuget package and they must not debug the class library.
- I need only me to use (
Debug/<ProjectReference>
) -> So I can change class library directly and build Nuget package for other people without PDB file,etc included.
What I try to do? What topics I read?
- I Following topics I follow:
Do I need change something?
CodePudding user response:
Currently there's no official solution for that.
So if anyone need what approach I collected and I modify some tags to prevent conflict PackageName with ProjectName, Here's final solution, Which original copied from https://github.com/dotnet/sdk/issues/1151#issuecomment-459275750 Many thanks to script author:
Here's enhancement version of it:
<PropertyGroup> <ReplacePackageReferences Condition="'$(ReplacePackageReferences)' == ''">true</ReplacePackageReferences> <ReplaceProjectReferences Condition="'$(ReplaceProjectReferences)' == ''">true</ReplaceProjectReferences> </PropertyGroup> <Choose> <When Condition="'$(SolutionPath)' != '' AND '$(SolutionPath)' != '*undefined*' AND Exists('$(SolutionPath)')"> <PropertyGroup> <SolutionFileContent>$([System.IO.File]::ReadAllText($(SolutionPath)))</SolutionFileContent> <SmartSolutionDir>$([System.IO.Path]::GetDirectoryName( $(SolutionPath) ))</SmartSolutionDir> <RegexPattern>(?<="[PackageName]", ")(.*)(?=", ")</RegexPattern> <HasSolution>true</HasSolution> </PropertyGroup> </When> <Otherwise> <PropertyGroup> <HasSolution>false</HasSolution> </PropertyGroup> </Otherwise> </Choose> <Choose> <When Condition="$(ReplacePackageReferences) AND $(HasSolution)"> <ItemGroup> <!-- Keep the identity of the packagereference --> <SmartPackageReference Include="@(PackageReference)"> <InProject>false</InProject> <PackageName>%(Identity)</PackageName> <InSolution>$(SolutionFileContent.Contains('\%(Identity).csproj'))</InSolution> </SmartPackageReference> <!-- Filter them by mapping them to another itemGroup using the WithMetadataValue item function --> <PackageInSolution Include="@(SmartPackageReference -> WithMetadataValue('InSolution', True) )"> <Pattern>$(RegexPattern.Replace('[PackageName]','%(PackageName)') )</Pattern> <SmartPath>$([System.Text.RegularExpressions.Regex]::Match( '$(SolutionFileContent)', '%(Pattern)' ))</SmartPath> <ProjName>'%(PackageName)'</ProjName> </PackageInSolution> <ProjectReference Include="@(PackageInSolution -> '$(SmartSolutionDir)\%(SmartPath)' )"> <Name>@(PackageInSolution -> %(ProjName))</Name> </ProjectReference> <!-- Remove the package references that are now referenced as projects --> <PackageReference Remove="@(PackageInSolution -> '%(PackageName)' )" /> </ItemGroup> </When> <When Condition="$(ReplaceProjectReferences) AND '$(_RestoreSolutionFileUsed)' == ''"> <ItemGroup> <!-- Keep the identity of the project reference (relative path), determine the project name and whether the project is contained in the current solution --> <SmartProjectReference Include="@(ProjectReference)"> <OriginalIdentity>%(Identity)</OriginalIdentity> <ProjectName>$([System.IO.Path]::GetFileNameWithoutExtension( $([System.IO.Path]::GetFullPath( '%(OriginalIdentity)' )) ))</ProjectName> <InSolution>$(SolutionFileContent.Contains('\%(ProjectName).csproj'))</InSolution> </SmartProjectReference> <!-- Filter them by mapping them to another itemGroup using the WithMetadataValue item function --> <ProjectNotInSolution Include="@(SmartProjectReference -> WithMetadataValue('InSolution', False) )"> </ProjectNotInSolution> <!--Reference the latest version of the package (why not * ? > see https://github.com/NuGet/Home/issues/7328--> <PackageReference Include="@(ProjectNotInSolution -> '%(ProjectName)' )" Version="*" /> <!-- Remove the project references that are now referenced as packages --> <ProjectReference Remove="@(ProjectNotInSolution -> '%(OriginalIdentity)' )" /> </ItemGroup> </When> </Choose>
Note if you need to auto update nuget package then you must specify the package above the script provided above:
<ItemGroup> <PackageReferen``ce Include="FooClassLibrary" Version="*"/> </ItemGroup>
Feel free to modify or edit above script or edit the answer. If you found better answer please post it (Ex You create new extension for that or something).