Skip to content

Commit eb89395

Browse files
[Xamarin.Android.Build.Tasks] remove $(UseShortFileNames) (#4946)
Setting `$(UseShortFileNames)`=`false` would tell Xamarin.Android's MSBuild targets to use "long" folder names such as: * `obj\Debug\lp` -> `__library_projects__` * `obj\Debug\lp\*\jl` -> `library_project_imports` * `obj\Debug\lp\*\nl` -> `native_library_imports` This was useful when `$(UseShortFileNames)` was a new feature, giving developers a way to "opt out" if they hit a bug. However, `$(UseShortFileNames)` has defaulted to `true` since ~July 2017 to help avoid the [MAX_PATH][0] limit on Windows. I'm finding basically [no usage of `UseShortFileNames=false`][1] on Github, which makes this an easy choice. I have removed all usage of `$(UseShortFileNames)`. The remaining behavior will act as if `$(UseShortFileNames)`=true. [0]: https://docs.microsoft.com/windows/win32/fileio/naming-a-file#maximum-path-length-limitation [1]: https://github.com/search?q=UseShortFileNames+false+extension%3Acsproj&type=Code
1 parent fd9c775 commit eb89395

File tree

16 files changed

+50
-72
lines changed

16 files changed

+50
-72
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### `UseShortFileNames=false` is no longer supported
2+
3+
In previous versions of Xamarin.Android, you could set
4+
`$(UseShortFileNames)` in your `.csproj` file:
5+
6+
```xml
7+
<PropertyGroup>
8+
<UseShortFileNames>false</UseShortFileNames>
9+
</PropertyGroup>
10+
```
11+
12+
This would tell Xamarin.Android's MSBuild targets to use the "long"
13+
folder names such as:
14+
15+
* `obj\Debug\lp` -> `__library_projects__`
16+
* `obj\Debug\lp\*\jl` -> `library_project_imports`
17+
* `obj\Debug\lp\*\nl` -> `native_library_imports`
18+
19+
This was useful when `$(UseShortFileNames)` was a new feature, giving
20+
developers a way to "opt out" if they hit a bug. However,
21+
`$(UseShortFileNames)` has defaulted to `true` since ~July 2017 to
22+
help the [MAX_PATH][0] limit on Windows.
23+
24+
This functionality has been removed from Xamarin.Android. Short file
25+
names will be used going forward.
26+
27+
[0]: https://docs.microsoft.com/windows/win32/fileio/naming-a-file#maximum-path-length-limitation

src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt.targets

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Copyright (C) 2019 Microsoft Corporation. All rights reserved.
4747
Condition="'$(_AndroidResourceDesignerFile)' != '' And '$(_AndroidUseAapt2)' != 'True'"
4848
ImportsDirectory="$(_LibraryProjectImportsDirectoryName)"
4949
OutputImportDirectory="$(_AndroidLibrayProjectIntermediatePath)"
50-
UseShortFileNames="$(UseShortFileNames)"
5150
JavaPlatformJarPath="$(JavaPlatformJarPath)"
5251
ManifestFiles="$(ResgenTemporaryDirectory)\AndroidManifest.xml"
5352
PackageName="$(_AndroidPackage)"
@@ -77,7 +76,6 @@ Copyright (C) 2019 Microsoft Corporation. All rights reserved.
7776
Condition="'$(_AndroidUseAapt2)' != 'True'"
7877
ImportsDirectory="$(_LibraryProjectImportsDirectoryName)"
7978
OutputImportDirectory="$(_AndroidLibrayProjectIntermediatePath)"
80-
UseShortFileNames="$(UseShortFileNames)"
8179
JavaPlatformJarPath="$(JavaPlatformJarPath)"
8280
ManifestFiles="$(IntermediateOutputPath)android\AndroidManifest.xml"
8381
ResourceDirectory="$(MonoAndroidResDirIntermediate)"

src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt2.targets

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
166166
ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)"
167167
AssemblyIdentityMapFile="$(_AndroidLibrayProjectAssemblyMapFile)"
168168
ImportsDirectory="$(_LibraryProjectImportsDirectoryName)"
169-
UseShortFileNames="$(UseShortFileNames)"
170169
OutputImportDirectory="$(_AndroidLibrayProjectIntermediatePath)"
171170
OutputFile="$(ResgenTemporaryDirectory)\resources.apk"
172171
PackageName="$(_AndroidPackage)"
@@ -231,7 +230,6 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
231230
ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)"
232231
ResourceDirectories="$(MonoAndroidResDirIntermediate)"
233232
AssemblyIdentityMapFile="$(_AndroidLibrayProjectAssemblyMapFile)"
234-
UseShortFileNames="$(UseShortFileNames)"
235233
ImportsDirectory="$(_LibraryProjectImportsDirectoryName)"
236234
OutputImportDirectory="$(_AndroidLibrayProjectIntermediatePath)"
237235
OutputFile="$(_PackagedResources)"

src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Core.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ It is shared between "legacy" binding projects and .NET 5 projects.
7373
TypeMappingReportFile="$(GeneratedOutputPath)type-mapping.txt"
7474
ToolPath="$(MonoAndroidToolsDirectory)"
7575
ToolExe="$(BindingsGeneratorToolExe)"
76-
UseShortFileNames="$(UseShortGeneratorFileNames)"
7776
LangVersion="$(LangVersion)"
7877
EnableInterfaceMembersPreview="$(_EnableInterfaceMembers)"
7978
/>

src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public class Aapt : AndroidAsyncTask
7373

7474
public string ImportsDirectory { get; set; }
7575
public string OutputImportDirectory { get; set; }
76-
public bool UseShortFileNames { get; set; }
7776
public string AssemblyIdentityMapFile { get; set; }
7877

7978
public string ResourceNameCaseMap { get; set; }
@@ -365,7 +364,7 @@ string ExpandString (string s)
365364
return s.Substring (0, st + 1) + ExpandString (s.Substring (st + 1));
366365
int ast = st + "${library.imports:".Length;
367366
string aname = s.Substring (ast, ed - ast);
368-
return s.Substring (0, st) + Path.Combine (OutputImportDirectory, UseShortFileNames ? assemblyMap.GetLibraryImportDirectoryNameForAssembly (aname) : aname, ImportsDirectory) + Path.DirectorySeparatorChar + ExpandString (s.Substring (ed + 1));
367+
return s.Substring (0, st) + Path.Combine (OutputImportDirectory, assemblyMap.GetLibraryImportDirectoryNameForAssembly (aname), ImportsDirectory) + Path.DirectorySeparatorChar + ExpandString (s.Substring (ed + 1));
369368
}
370369
else
371370
return s;

src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Link.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ public class Aapt2Link : Aapt2 {
7171

7272
public string ImportsDirectory { get; set; }
7373

74-
public bool UseShortFileNames { get; set; }
75-
7674
public bool NonConstantId { get; set; }
7775

7876
public bool ProtobufFormat { get; set; }
@@ -296,7 +294,7 @@ string ExpandString (string s)
296294
return s.Substring (0, st + 1) + ExpandString (s.Substring (st + 1));
297295
int ast = st + "${library.imports:".Length;
298296
string aname = s.Substring (ast, ed - ast);
299-
return s.Substring (0, st) + Path.Combine (OutputImportDirectory, UseShortFileNames ? assemblyMap.GetLibraryImportDirectoryNameForAssembly (aname) : aname, ImportsDirectory) + Path.DirectorySeparatorChar + ExpandString (s.Substring (ed + 1));
297+
return s.Substring (0, st) + Path.Combine (OutputImportDirectory, assemblyMap.GetLibraryImportDirectoryNameForAssembly (aname), ImportsDirectory) + Path.DirectorySeparatorChar + ExpandString (s.Substring (ed + 1));
300298
}
301299
else
302300
return s;

src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ public class ResolveLibraryProjectImports : AndroidTask
3535

3636
public ITaskItem [] AarLibraries { get; set; }
3737

38-
[Required]
39-
public bool UseShortFileNames { get; set; }
40-
4138
[Required]
4239
public string AssemblyIdentityMapFile { get; set; }
4340

@@ -174,10 +171,7 @@ void Extract (
174171
continue;
175172
}
176173
string assemblyFileName = Path.GetFileNameWithoutExtension (assemblyPath);
177-
string assemblyIdentName = assemblyFileName;
178-
if (UseShortFileNames) {
179-
assemblyIdentName = assemblyMap.GetLibraryImportDirectoryNameForAssembly (assemblyFileName);
180-
}
174+
string assemblyIdentName = assemblyMap.GetLibraryImportDirectoryNameForAssembly (assemblyFileName);
181175
string outDirForDll = Path.Combine (OutputImportDirectory, assemblyIdentName);
182176
string importsDir = Path.Combine (outDirForDll, ImportsDirectory);
183177
string nativeimportsDir = Path.Combine (outDirForDll, NativeImportsDirectory);
@@ -336,9 +330,7 @@ void Extract (
336330
if (!File.Exists (aarFile.ItemSpec))
337331
continue;
338332
string aarIdentityName = Path.GetFileNameWithoutExtension (aarFile.ItemSpec);
339-
if (UseShortFileNames) {
340-
aarIdentityName = assemblyMap.GetLibraryImportDirectoryNameForAssembly (aarIdentityName);
341-
}
333+
aarIdentityName = assemblyMap.GetLibraryImportDirectoryNameForAssembly (aarIdentityName);
342334
string outDirForDll = Path.Combine (OutputImportDirectory, aarIdentityName);
343335
string importsDir = Path.Combine (outDirForDll, ImportsDirectory);
344336
string resDir = Path.Combine (importsDir, "res");

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public void BindngFilterUnsupportedNativeAbiLibraries ()
298298
}
299299

300300
[Test]
301-
public void BindingCheckHiddenFiles ([Values (true, false)] bool useShortFileNames)
301+
public void BindingCheckHiddenFiles ()
302302
{
303303
var binding = new XamarinAndroidBindingProject () {
304304
UseLatestPlatformSdk = true,
@@ -312,13 +312,11 @@ public void BindingCheckHiddenFiles ([Values (true, false)] bool useShortFileNam
312312
WebContentFileNameFromAzure = "javaBindingIssue.jar"
313313
});
314314
var path = Path.Combine ("temp", TestContext.CurrentContext.Test.Name);
315-
binding.SetProperty (binding.ActiveConfigurationProperties, "UseShortFileNames", useShortFileNames);
316315
using (var bindingBuilder = CreateDllBuilder (Path.Combine (path, "Binding"))) {
317316
bindingBuilder.Verbosity = Microsoft.Build.Framework.LoggerVerbosity.Diagnostic;
318317
Assert.IsTrue (bindingBuilder.Build (binding), "binding build should have succeeded");
319318
var proj = new XamarinAndroidApplicationProject ();
320319
proj.OtherBuildItems.Add (new BuildItem ("ProjectReference", "..\\Binding\\UnnamedProject.csproj"));
321-
proj.SetProperty (proj.ActiveConfigurationProperties, "UseShortFileNames", useShortFileNames);
322320
proj.AndroidManifest = $@"<?xml version=""1.0"" encoding=""utf-8""?>
323321
<manifest xmlns:android=""http://schemas.android.com/apk/res/android"" xmlns:tools=""http://schemas.android.com/tools"" android:versionCode=""1"" android:versionName=""1.0"" package=""{proj.PackageName}"">
324322
<uses-sdk />
@@ -328,21 +326,13 @@ public void BindingCheckHiddenFiles ([Values (true, false)] bool useShortFileNam
328326
using (var b = CreateApkBuilder (Path.Combine (path, "App"))) {
329327
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
330328
var assemblyMap = b.Output.GetIntermediaryPath (Path.Combine ("lp", "map.cache"));
331-
if (useShortFileNames)
332-
Assert.IsTrue (File.Exists (assemblyMap), $"{assemblyMap} should exist.");
333-
else
334-
Assert.IsFalse (File.Exists (assemblyMap), $"{assemblyMap} should not exist.");
329+
Assert.IsTrue (File.Exists (assemblyMap), $"{assemblyMap} should exist.");
335330
var assemblyIdentityMap = new List<string> ();
336-
if (useShortFileNames) {
337-
foreach (var s in File.ReadLines (assemblyMap)) {
338-
assemblyIdentityMap.Add (s);
339-
}
331+
foreach (var s in File.ReadLines (assemblyMap)) {
332+
assemblyIdentityMap.Add (s);
340333
}
341-
var assmeblyIdentity = useShortFileNames ? assemblyIdentityMap.IndexOf ("UnnamedProject").ToString () : "UnnamedProject";
342-
var libaryImportsFolder = useShortFileNames ? "lp" : "__library_projects__";
343-
var jlibs = useShortFileNames ? "jl" : "library_project_imports";
344-
var dsStorePath = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, libaryImportsFolder,
345-
assmeblyIdentity, jlibs);
334+
var assemblyIdentity = assemblyIdentityMap.IndexOf ("UnnamedProject").ToString ();
335+
var dsStorePath = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "lp", assemblyIdentity, "jl");
346336
Assert.IsTrue (Directory.Exists (dsStorePath), "{0} should exist.", dsStorePath);
347337
Assert.IsFalse (File.Exists (Path.Combine (dsStorePath, ".DS_Store")), "{0} should NOT exist.",
348338
Path.Combine (dsStorePath, ".DS_Store"));

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,7 +2962,7 @@ public void BuildInDesignTimeMode ([Values(false, true)] bool useManagedParser)
29622962
}
29632963

29642964
[Test]
2965-
public void CheckLibraryImportsUpgrade ([Values(false, true)] bool useShortFileNames)
2965+
public void CheckLibraryImportsUpgrade ()
29662966
{
29672967
var path = Path.Combine ("temp", TestContext.CurrentContext.Test.Name);
29682968
var libproj = new XamarinAndroidLibraryProject () {
@@ -2975,7 +2975,6 @@ public void CheckLibraryImportsUpgrade ([Values(false, true)] bool useShortFileN
29752975
};
29762976
proj.References.Add (new BuildItem ("ProjectReference", $"..\\Library1\\Library1.csproj"));
29772977
proj.SetProperty ("_AndroidLibrayProjectIntermediatePath", Path.Combine (proj.IntermediateOutputPath, "__library_projects__"));
2978-
proj.SetProperty (proj.ActiveConfigurationProperties, "UseShortFileNames", useShortFileNames);
29792978
using (var libb = CreateDllBuilder (Path.Combine (path, libproj.ProjectName), false, false)) {
29802979
Assert.IsTrue (libb.Build (libproj), "Build should have succeeded.");
29812980
using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName), false, false)) {
@@ -2985,13 +2984,8 @@ public void CheckLibraryImportsUpgrade ([Values(false, true)] bool useShortFileN
29852984
"The __library_projects__ directory should exist.");
29862985
proj.RemoveProperty ("_AndroidLibrayProjectIntermediatePath");
29872986
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
2988-
if (useShortFileNames) {
2989-
Assert.IsFalse (Directory.Exists (Path.Combine (Root, path, proj.ProjectName, proj.IntermediateOutputPath, "__library_projects__")),
2990-
"The __library_projects__ directory should not exist, due to IncrementalClean.");
2991-
} else {
2992-
Assert.IsTrue (Directory.Exists (Path.Combine (Root, path, proj.ProjectName, proj.IntermediateOutputPath, "__library_projects__")),
2993-
"The __library_projects__ directory should exist.");
2994-
}
2987+
Assert.IsFalse (Directory.Exists (Path.Combine (Root, path, proj.ProjectName, proj.IntermediateOutputPath, "__library_projects__")),
2988+
"The __library_projects__ directory should not exist, due to IncrementalClean.");
29952989
Assert.IsTrue (libb.Clean (libproj), "Clean should have succeeded.");
29962990
Assert.IsTrue (libb.Build (libproj), "Build should have succeeded.");
29972991
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
@@ -3000,15 +2994,10 @@ public void CheckLibraryImportsUpgrade ([Values(false, true)] bool useShortFileN
30002994
using (var zip = ZipHelper.OpenZip (zipFile)) {
30012995
Assert.IsTrue (zip.ContainsEntry ("library_project_imports/__res_name_case_map.txt"), $"{zipFile} should contain a library_project_imports/__res_name_case_map.txt entry");
30022996
}
3003-
if (!useShortFileNames) {
3004-
Assert.IsTrue (Directory.Exists (Path.Combine (Root, path, proj.ProjectName, proj.IntermediateOutputPath, "__library_projects__")),
3005-
"The __library_projects__ directory should exist.");
3006-
} else {
3007-
Assert.IsFalse (Directory.Exists (Path.Combine (Root, path, proj.ProjectName, proj.IntermediateOutputPath, "__library_projects__")),
3008-
"The __library_projects__ directory should not exist.");
3009-
Assert.IsTrue (Directory.Exists (Path.Combine (Root, path, proj.ProjectName, proj.IntermediateOutputPath, "lp")),
3010-
"The lp directory should exist.");
3011-
}
2997+
Assert.IsFalse (Directory.Exists (Path.Combine (Root, path, proj.ProjectName, proj.IntermediateOutputPath, "__library_projects__")),
2998+
"The __library_projects__ directory should not exist.");
2999+
Assert.IsTrue (Directory.Exists (Path.Combine (Root, path, proj.ProjectName, proj.IntermediateOutputPath, "lp")),
3000+
"The lp directory should exist.");
30123001

30133002
}
30143003
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/IncrementalBuildTest.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public TestMe createTestMe () {
235235

236236
[Test]
237237
[Category ("dotnet")]
238-
public void ResolveNativeLibrariesInManagedReferences ([Values(true, false)] bool useShortFileNames)
238+
public void ResolveNativeLibrariesInManagedReferences ()
239239
{
240240
var lib = new XamarinAndroidLibraryProject () {
241241
ProjectName = "Lib",
@@ -263,7 +263,6 @@ public Class1 ()
263263
},
264264
},
265265
};
266-
lib.SetProperty (lib.ActiveConfigurationProperties, "UseShortFileNames", useShortFileNames);
267266
var so = lib.OtherBuildItems.First (x => x.Include () == "libs/armeabi-v7a/libfoo.so");
268267

269268
var lib2 = new XamarinAndroidLibraryProject () {
@@ -295,8 +294,7 @@ public Class2 ()
295294
},
296295
},
297296
};
298-
lib2.SetProperty (lib.ActiveConfigurationProperties, "UseShortFileNames", useShortFileNames);
299-
var path = Path.Combine (Root, "temp", $"ResolveNativeLibrariesInManagedReferences_{useShortFileNames}");
297+
var path = Path.Combine (Root, "temp", TestName);
300298
using (var libbuilder = CreateDllBuilder (Path.Combine(path, "Lib"))) {
301299

302300
Assert.IsTrue (libbuilder.Build (lib), "lib 1st. build failed");
@@ -312,7 +310,6 @@ public Class2 ()
312310
}
313311
};
314312
app.SetAndroidSupportedAbis ("armeabi-v7a");
315-
app.SetProperty (app.ActiveConfigurationProperties, "UseShortFileNames", useShortFileNames);
316313
using (var builder = CreateApkBuilder (Path.Combine (path, "App"))) {
317314
builder.Verbosity = LoggerVerbosity.Diagnostic;
318315
Assert.IsTrue (builder.Build (app), "app 1st. build failed");
@@ -330,7 +327,7 @@ public Class2 ()
330327
Assert.IsNotNull (libfoo, "libfoo.so should exist in the .apk");
331328

332329
Assert.AreEqual (so.TextContent ().Length, new FileInfo (Path.Combine (Root, libbuilder.ProjectDirectory, lib.IntermediateOutputPath,
333-
useShortFileNames ? "nl" : "native_library_imports", "armeabi-v7a", "libfoo.so")).Length,
330+
"nl", "armeabi-v7a", "libfoo.so")).Length,
334331
"intermediate size mismatch");
335332
libfoo = ZipHelper.ReadFileFromZip (Path.Combine (Root, builder.ProjectDirectory, app.OutputPath, app.PackageName + "-Signed.apk"),
336333
"lib/armeabi-v7a/libfoo.so");

0 commit comments

Comments
 (0)