0

In my case, I have a csproj file which looks like

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\LocalLibrary\LocalLibrary.csproj" />
  </ItemGroup>

</Project>

When other developers clone and work on the project, they may place LocalLibrary in different locations...

So I want the remote to only contain

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>

</Project>

And then when they add their own reference to the project, and their csproj file is updated accordingly, git will ignore that addition.

I imagine this is the only change that will ever be made to the csproj file, and if not (e.g. adding a new package dependency) they can add -f and "hack around" in their rare cases to update the remote.

So I thought at first I would try:

  1. Commit the desired partial of that file, as shown in the second formatted block above
  2. Update the gitignore to ignore this file
  3. Commit the new gitignore
  4. Hey presto! All future changes to the csproj ignored

But actually after step 3, git status still shows Modified: x.csproj.

I looked it up, looks like this can be resolved by committing a git rm --cached x.csproj, but that will also delete the file from the remote... which I don't want.

I want to have the template of the file in the remote, but ignore developers' local individual changes to it.

How can I resolve this?

theonlygusti
  • 11,032
  • 11
  • 64
  • 119
  • If you want a template in the remote, why not make the file an actual template? Something akin to `csproj.template`, and never commit the actual file. This way, nobody can trample anybody else's working copy with their local paths. – Stephen Newell Jul 10 '20 at 21:40
  • @StephenNewell I was hoping git would have a solution. So that there wasn't always lying around this unused file. – theonlygusti Jul 11 '20 at 07:19

0 Answers0