最近,我们通过156个项目在解决方案上运行了CSPROJ迁移工具:
dotnet tool install --global Project2015To2017.Migrate2019.Tool
尽管我们必须进行一些修改,但效果很好。但是,这引起了一个问题,即更改之前和之后的分支之间会导致汇编的问题。
错误是:
Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [PROJECTNAME]
我相信这是因为新格式正在放置gasseblyInfo.cs,而旧样式的csproj在某种程度上是在选择这个?您可以在此处看到它在文件中引起的问题:
PROJECTNAMEe\obj\x64\Debug\.NETFramework,Version=v4.7.2.AssemblyAttributes.cs
可以通过运行来解决:
1. Close Visual studio/Rider
2. git clean -xfd
3. Get-ChildItem . -Include obj, .vs -Recurse -force | Remove-Item -Recurse -Force
4. Rebuild solution
现在 works ,但是我们不断提醒自己做到这一点很烦人。有没有一种方法可以修改我们的新CSPROJ,以免这样做?
We recently ran the csproj migration tool on our solution with 156 projects:
dotnet tool install --global Project2015To2017.Migrate2019.Tool
This worked very well although we had to do a few modifications. However it has caused a problem where switching between branches before and after the change causes problems with the assemblyinfo.
The error is:
Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [PROJECTNAME]
I believe this is because the new format is putting an assemblyinfo.cs and the old style csproj is somehow picking this up? You can see this here where it takes issue with a file:
PROJECTNAMEe\obj\x64\Debug\.NETFramework,Version=v4.7.2.AssemblyAttributes.cs
This can be fixed by running:
1. Close Visual studio/Rider
2. git clean -xfd
3. Get-ChildItem . -Include obj, .vs -Recurse -force | Remove-Item -Recurse -Force
4. Rebuild solution
Now this works but it's irritating that we constantly have to remind ourselves to do this. Is there a way to modify our new csprojs to make it not do this?
发布评论
评论(1)
在新的项目样式中,“汇编信息相关的属性”在
.csproj
项目文件中定义,而旧样式在assemblyInfo.cs
文件中具有该属性。在构建时间,这些进入自动生成的
.cs
file;在这里,
.netFramework,版本= v4.7.2.2.semblyattributes.cs
file。由于该文件不在项目之外,因此在切换项目样式(通过Branche Switches)时不会清理。
最终以这些 /code> 错误是因为与
assemblyInfo.cs
文件中的信息发生冲突。您可以通过在
.csproj
文件中添加以下设置来防止新样式项目自动生成此类assemblyAttributes.cs
文件。这样,这确实意味着您必须在已经转换的项目中还原这些
assemblyInfo.cs
文件。如果可能的话,您可以再次运行迁移,并应用
keep-emembly-info
。或者(如果这些旧的项目样式分支相当暂时并且有时间存在),您也可以考虑在这些分支上工作时第二次将存储库克隆到单独的路径上。这样做,他们不共享相同的输出文件夹。
In the new project style, the assembly info related properties are defined in the
.csproj
project file, whereas the old style has this in theAssemblyInfo.cs
file.At build time, these go into an auto generated
.cs
file;here that
.NETFramework,Version=v4.7.2.AssemblyAttributes.cs
file.Since that file is outside of the project, it doesn't get cleaned up when switching project styles (via branche switches).
This ends up in these
CS0579
errors because of the conflicts with the info in theAssemblyInfo.cs
files in your old project styled projects.You can prevent the new style projects from auto generating such
AssemblyAttributes.cs
files, by adding the below setting in the.csproj
file.This then does mean that you have to restore these
AssemblyInfo.cs
files in the already converted projects.If possible, you might run the migration again and apply the
keep-assembly-info
flag.Alternatively (in case these old project style branches are rather temporary and for time being), you might also consider to clone the repository a second time to a separate path when working on these branches. Doing so they don't share the same output folders.