Skip to content

Commit

Permalink
Next steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Forgind committed Aug 3, 2020
1 parent 036c5a3 commit 8b3b613
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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; } }
Expand Down
1 change: 1 addition & 0 deletions src/Tasks/Microsoft.Build.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@
<ItemGroup>
<!-- Reference this package to get binaries at runtime even when Arcade is not adding compiler references -->
<PackageReference Include="Microsoft.Net.Compilers.Toolset" ExcludeAssets="all" Condition="'$(UsingToolMicrosoftNetCompilers)' == 'false'" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
Expand Down
63 changes: 25 additions & 38 deletions src/Tasks/StateFileBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Tasks/SystemState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
/// Gets the last modified date.
/// </summary>
/// <value></value>
internal DateTime LastModified
public DateTime LastModified
{
get { return lastModified; }
set { lastModified = value; }
Expand All @@ -211,7 +211,7 @@ internal DateTime LastModified
/// Get or set the assemblyName.
/// </summary>
/// <value></value>
internal AssemblyNameExtension Assembly
public AssemblyNameExtension Assembly
{
get { return assemblyName; }
set { assemblyName = value; }
Expand All @@ -221,7 +221,7 @@ internal AssemblyNameExtension Assembly
/// Get or set the runtimeVersion
/// </summary>
/// <value></value>
internal string RuntimeVersion
public string RuntimeVersion
{
get { return runtimeVersion; }
set { runtimeVersion = value; }
Expand All @@ -231,7 +231,7 @@ internal string RuntimeVersion
/// Get or set the framework name the file was built against
/// </summary>
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Could be used in other assemblies")]
internal FrameworkName FrameworkNameAttribute
public FrameworkName FrameworkNameAttribute
{
get { return frameworkName; }
set { frameworkName = value; }
Expand All @@ -240,13 +240,13 @@ internal FrameworkName FrameworkNameAttribute
/// <summary>
/// Get or set the ID of this assembly. Used to verify it is the same version.
/// </summary>
internal Guid ModuleVersionID { get; set; }
public Guid ModuleVersionID { get; set; }
}

/// <summary>
/// Construct.
/// </summary>
internal SystemState()
public SystemState()
{
}

Expand Down

0 comments on commit 8b3b613

Please sign in to comment.