diff --git a/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs b/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs
index c2eaad8de59..504910a4ea2 100644
--- a/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs
+++ b/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs
@@ -884,6 +884,8 @@ public ResolveAssemblyReference() { }
public Microsoft.Build.Framework.ITaskItem[] Assemblies { get { throw null; } set { } }
public Microsoft.Build.Framework.ITaskItem[] AssemblyFiles { get { throw null; } set { } }
public bool AutoUnify { get { throw null; } set { } }
+ public string[] CacheInputPaths { get { throw null; } set { } }
+ public string CacheOutputPath { get { throw null; } set { } }
public string[] CandidateAssemblyFiles { get { throw null; } set { } }
public bool CopyLocalDependenciesWhenParentReferenceInGac { get { throw null; } set { } }
[Microsoft.Build.Framework.OutputAttribute]
@@ -910,8 +912,6 @@ public ResolveAssemblyReference() { }
public Microsoft.Build.Framework.ITaskItem[] InstalledAssemblySubsetTables { get { throw null; } set { } }
public Microsoft.Build.Framework.ITaskItem[] InstalledAssemblyTables { get { throw null; } set { } }
public string[] LatestTargetFrameworkDirectories { get { throw null; } set { } }
- public string[] PreComputedCacheFileList { get { throw null; } set { } }
- public string PreComputedCacheOutputPath { get { throw null; } set { } }
public string ProfileName { get { throw null; } set { } }
[Microsoft.Build.Framework.OutputAttribute]
public Microsoft.Build.Framework.ITaskItem[] RelatedFiles { get { throw null; } }
diff --git a/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs b/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs
index 60821f9b1db..a1d7750c4df 100644
--- a/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs
+++ b/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs
@@ -542,6 +542,8 @@ public ResolveAssemblyReference() { }
public Microsoft.Build.Framework.ITaskItem[] Assemblies { get { throw null; } set { } }
public Microsoft.Build.Framework.ITaskItem[] AssemblyFiles { get { throw null; } set { } }
public bool AutoUnify { get { throw null; } set { } }
+ public string[] CacheInputPaths { get { throw null; } set { } }
+ public string CacheOutputPath { get { throw null; } set { } }
public string[] CandidateAssemblyFiles { get { throw null; } set { } }
public bool CopyLocalDependenciesWhenParentReferenceInGac { get { throw null; } set { } }
[Microsoft.Build.Framework.OutputAttribute]
@@ -568,8 +570,6 @@ public ResolveAssemblyReference() { }
public Microsoft.Build.Framework.ITaskItem[] InstalledAssemblySubsetTables { get { throw null; } set { } }
public Microsoft.Build.Framework.ITaskItem[] InstalledAssemblyTables { get { throw null; } set { } }
public string[] LatestTargetFrameworkDirectories { get { throw null; } set { } }
- public string[] PreComputedCacheFileList { get { throw null; } set { } }
- public string PreComputedCacheOutputPath { get { throw null; } set { } }
public string ProfileName { get { throw null; } set { } }
[Microsoft.Build.Framework.OutputAttribute]
public Microsoft.Build.Framework.ITaskItem[] RelatedFiles { get { throw null; } }
diff --git a/src/Tasks/Microsoft.Build.Tasks.csproj b/src/Tasks/Microsoft.Build.Tasks.csproj
index b13e439a3c7..42b7444e5c2 100644
--- a/src/Tasks/Microsoft.Build.Tasks.csproj
+++ b/src/Tasks/Microsoft.Build.Tasks.csproj
@@ -986,6 +986,7 @@
+
diff --git a/src/Tasks/StateFileBase.cs b/src/Tasks/StateFileBase.cs
index 8a48a986219..3eb868b682c 100644
--- a/src/Tasks/StateFileBase.cs
+++ b/src/Tasks/StateFileBase.cs
@@ -7,6 +7,7 @@
using Microsoft.Build.Utilities;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;
+using System.Text.Json;
namespace Microsoft.Build.Tasks
{
@@ -36,16 +37,7 @@ internal virtual void SerializeCache(string stateFile, TaskLoggingHelper log)
{
if (!string.IsNullOrEmpty(stateFile))
{
- if (FileSystems.Default.FileExists(stateFile))
- {
- File.Delete(stateFile);
- }
-
- using (var s = new FileStream(stateFile, FileMode.CreateNew))
- {
- var formatter = new BinaryFormatter();
- formatter.Serialize(s, this);
- }
+ File.WriteAllText(stateFile, JsonSerializer.Serialize(this));
}
}
catch (Exception e)
@@ -74,39 +66,34 @@ internal static StateFileBase DeserializeCache(string stateFile, TaskLoggingHelp
{
if (!string.IsNullOrEmpty(stateFile) && FileSystems.Default.FileExists(stateFile))
{
- using (FileStream s = new FileStream(stateFile, FileMode.Open))
+ object deserializedObject = JsonSerializer.Deserialize(File.ReadAllText(stateFile), requiredReturnType);
+ retVal = deserializedObject as StateFileBase;
+ // If the deserialized object is null then there would be no cast error but retVal would still be null
+ // only log the message if there would have been a cast error
+ if (retVal == null && deserializedObject != null)
{
- var formatter = new BinaryFormatter();
- object deserializedObject = formatter.Deserialize(s);
- retVal = deserializedObject as StateFileBase;
-
- // If the deserialized object is null then there would be no cast error but retVal would still be null
- // only log the message if there would have been a cast error
- if (retVal == null && deserializedObject != null)
- {
- // When upgrading to Visual Studio 2008 and running the build for the first time the resource cache files are replaced which causes a cast error due
- // to a new version number on the tasks class. "Unable to cast object of type 'Microsoft.Build.Tasks.SystemState' to type 'Microsoft.Build.Tasks.StateFileBase".
- // If there is an invalid cast, a message rather than a warning should be emitted.
- log.LogMessageFromResources("General.CouldNotReadStateFileMessage", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
- }
- else if (retVal != null && (!requiredReturnType.IsInstanceOfType(retVal)))
+ // When upgrading to Visual Studio 2008 and running the build for the first time the resource cache files are replaced which causes a cast error due
+ // to a new version number on the tasks class. "Unable to cast object of type 'Microsoft.Build.Tasks.SystemState' to type 'Microsoft.Build.Tasks.StateFileBase".
+ // If there is an invalid cast, a message rather than a warning should be emitted.
+ log.LogMessageFromResources("General.CouldNotReadStateFileMessage", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
+ }
+ else if (retVal != null && (!requiredReturnType.IsInstanceOfType(retVal)))
+ {
+ if (logWarnings)
{
- if (logWarnings)
- {
- log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
- }
- else
- {
- log.LogMessageFromResources("General.CouldNotReadStateFile", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
- }
- retVal = null;
+ log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
}
- // If we get back a valid object and internals were changed, things are likely to be null. Check the version before we use it.
- else if (retVal != null && retVal._serializedVersion != CurrentSerializationVersion)
+ else
{
- log.LogMessageFromResources("General.CouldNotReadStateFileMessage", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
- retVal = null;
+ log.LogMessageFromResources("General.CouldNotReadStateFile", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
}
+ retVal = null;
+ }
+ // If we get back a valid object and internals were changed, things are likely to be null. Check the version before we use it.
+ else if (retVal != null && retVal._serializedVersion != CurrentSerializationVersion)
+ {
+ log.LogMessageFromResources("General.CouldNotReadStateFileMessage", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
+ retVal = null;
}
}
}
diff --git a/src/Tasks/SystemState.cs b/src/Tasks/SystemState.cs
index b663f73c5a3..b54c97f8896 100644
--- a/src/Tasks/SystemState.cs
+++ b/src/Tasks/SystemState.cs
@@ -201,7 +201,7 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
/// Gets the last modified date.
///
///
- internal DateTime LastModified
+ public DateTime LastModified
{
get { return lastModified; }
set { lastModified = value; }
@@ -211,7 +211,7 @@ internal DateTime LastModified
/// Get or set the assemblyName.
///
///
- internal AssemblyNameExtension Assembly
+ public AssemblyNameExtension Assembly
{
get { return assemblyName; }
set { assemblyName = value; }
@@ -221,7 +221,7 @@ internal AssemblyNameExtension Assembly
/// Get or set the runtimeVersion
///
///
- internal string RuntimeVersion
+ public string RuntimeVersion
{
get { return runtimeVersion; }
set { runtimeVersion = value; }
@@ -231,7 +231,7 @@ internal string RuntimeVersion
/// Get or set the framework name the file was built against
///
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Could be used in other assemblies")]
- internal FrameworkName FrameworkNameAttribute
+ public FrameworkName FrameworkNameAttribute
{
get { return frameworkName; }
set { frameworkName = value; }
@@ -240,13 +240,13 @@ internal FrameworkName FrameworkNameAttribute
///
/// Get or set the ID of this assembly. Used to verify it is the same version.
///
- internal Guid ModuleVersionID { get; set; }
+ public Guid ModuleVersionID { get; set; }
}
///
/// Construct.
///
- internal SystemState()
+ public SystemState()
{
}