2

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

https://github.com/RicoSuter/NuGetReferenceSwitcher

or

https://github.com/0UserName/NuGetSwitcher

but above repos are not updated to VS 2022? please any help?

Edit: Looks like other people asks about that issue: https://github.com/dotnet/sdk/issues/1151

Shortly, I need to make a Class Library project can modify/edit in my side only. Other people only use DLL reference or Nuget package.

What I need to do?

  1. I need to create a main project that used across me as public source and other people as DLL only not debuggable.
  2. In my side the class library project must seen if I choose MSBuild configuration (Debug mode) not Nuget DLL. but I need to modify whole core source. Then republish it again as Nuget to allow other people to use it privately. Configuration Options
  3. I guess the whole gape in main project .csproj file. I need to modify it to allow Configuration to switch between Nuget build that visible to other developers and Debug that only visible at me. When choose it the <ProjectReference> should load and should become visible at my solution.
  4. You can ignore Github things I mentioned. A repo can be private/public wihtout problem.

Problem Short Description:

  1. I have main project in solution A. (Must be GIT public for other people)
  2. I have class library in solution B (Which maybe used in 2 main projects) (Must be GIT private repo for me only)
  3. I need the class library source only visible for me not other people. they just see Package or DLL.
  4. The main project are public Git repo, while class library are private Git repo.
  5. In my case I need to setup a 2 types of MSBuild configuration. (Debug/) and (Nuget/ )
  6. the other people only allowed to use which are private nuget package and they must not debug the class library.
  7. 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?

  1. I Following topics I follow: Use local source code of NuGet package to debug and edit code (@Mr Qian comment)

and https://sitecore.stackexchange.com/questions/15293/what-are-packagereferences-and-how-will-they-help-optimise-the-way-i-deal-with-n/15294

  1. I create two solutions. First (FooProject Executable), Second(FooClassLibrary)

  2. I modify the FooProject.csproj and add following lines

     <ItemGroup Condition="'$(Configuration)' == 'Debug'">
       <ProjectReference 
       Include="..\..\FooClassLibrary\FooClassLibrary\FooClassLibrary.csproj">
           <Project>{a2329af5-316e-4339-8b56-d78aba72e919}</Project>
           <Name>FooClassLibrary</Name>
      </ProjectReference>
    </ItemGroup>
    <ItemGroup Condition="'$(Configuration)' == 'Release'">
      <Reference Include="FooClassLibrary">
      <HintPath>..\..\FooClassLibrary\FooClassLibrary\bin\Release\FooClassLibrary.dll> 
      </HintPath>
      </Reference>
    </ItemGroup>
    

Edit:

I fix issues in above .csproj code. Now class library referenced with two MSBuild configuration (Debug and Release). But I don't add Class Libray in FooProject solution in Debug MSBuild.

Should now I create two solutions *.sln files? one for FooProject and reference with FooClassLibrary as DLL for non-modifying debugging? And second FooProject solution (FooClassDebuggingAndEdit.sln) that reference project to FooProject?

Here's a two solutions *.rar link https://anonfiles.com/rdm8A4I2x9/TwoSolutions_rar

I don't know why a solution should also reference the ClassLibrary project or it can't modified when do <ReferenceProject> in FooProject. I got following error message when debug: Error Message Screenshot

Do I need change something?

nickgreek
  • 181
  • 1
  • 7

1 Answers1

0

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>(?&lt;="[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 -&gt; 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 -&gt; %(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 -&gt; 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).

nickgreek
  • 181
  • 1
  • 7