Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ internal TaskLoggingHelper TaskLogger
set { _taskLogger = value; }
}

/// <summary>
/// Support custom IntermediateOutputPath and BaseIntermediateOutputPath outside the project path
/// </summary>
internal bool SupportCustomOutputPaths { get; set; } = false;

// If the xaml has local references, then it could have internal element & properties
// but there is no way to determine this until MCPass2. Yet, GeneratedInternalTypeHelper,
// which is the class that allows access to legitimate internals, needs to be generated
Expand Down Expand Up @@ -1575,11 +1580,64 @@ private string ParentFolderPrefix
{
get
{
#if NETFX
return PathInternal.GetRelativePath(TargetPath, SourceFileInfo.SourcePath, StringComparison.OrdinalIgnoreCase) + Path.DirectorySeparatorChar;
if (SupportCustomOutputPaths)
{
// During code generation, ParentFolderPrefix returns the relative path from a .g.cs file to its markup file.
//
// One example is generated #pragmas: #pragma checksum "..\..\..\..\Views\ExportNotificationView.xaml"
//
// The path information for a markup file is represented in SourceFileInfo:
//
// SourceFileInfo.OriginalFilePath: "c:\\greenshot\\src\\Greenshot.Addons\\Views\\ExportNotificationView.xaml"
// SourceFileInfo.TargetPath: "c:\\greenshot\\src\\Greenshot.Addons\\obj\\Debug\\net6.0-windows\\"
// SourceFileInfo.RelativeFilePath: "Views\\ExportNotificationView"
// SourceFileInfo.SourcePath = "c:\\greenshot\\src\\Greenshot.Addons\\"
//
// The path of the generated code file associated with this markup file is:
//
// "c:\greenshot\src\Greenshot.Addons\obj\Debug\net6.0-windows\Views\ExportNotificationView.g.cs"
//
// The markup file path is in SourceFileInfo.OriginalFilePath:
//
// "c:\\greenshot\\src\\Greenshot.Addons\\Views\\ExportNotificationView.xaml"
//
// The relative path calculation must take in to account both the TargetPath and the RelativeFilePath:
//
// "c:\\greenshot\\src\\Greenshot.Addons\\obj\\Debug\\net6.0-windows\\" [SourceFileInfo.TargetPath]
// "Views\\ExportNotificationView" [SourceFileInfo.RelativeTargetPath]
//
// TargetPath concatenated with the directory portion of the RelativeTargetPath is the location to the .g.cs file:
//
// "c:\\greenshot\\src\\Greenshot.Addons\\obj\\Debug\\net6.0-windows\\Views"
//
string pathOfRelativeSourceFilePath = System.IO.Path.GetDirectoryName(SourceFileInfo.RelativeSourceFilePath);

// Return the parent folder of the target file with a trailing DirectorySeparatorChar.
// Return a relative path if possible. Else, return an absolute path.
#if NETFX
string path = PathInternal.GetRelativePath(TargetPath + pathOfRelativeSourceFilePath, SourceFileInfo.SourcePath, StringComparison.OrdinalIgnoreCase);
#else
return Path.GetRelativePath(TargetPath, SourceFileInfo.SourcePath) + Path.DirectorySeparatorChar;
string path = Path.GetRelativePath(TargetPath + pathOfRelativeSourceFilePath, SourceFileInfo.SourcePath);
#endif
// Always return a path with a trailing DirectorySeparatorChar.
return path.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
}
else
{
string parentFolderPrefix = string.Empty;
if (TargetPath.StartsWith(SourceFileInfo.SourcePath, StringComparison.OrdinalIgnoreCase))
{
string relPath = TargetPath.Substring(SourceFileInfo.SourcePath.Length);
relPath += SourceFileInfo.RelativeSourceFilePath;
string[] dirs = relPath.Split(new Char[] { Path.DirectorySeparatorChar });
for (int i = 1; i < dirs.Length; i++)
{
parentFolderPrefix += PARENTFOLDER;
}
}

return parentFolderPrefix;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ internal int ErrorTimes
get { return _nErrors; }
}

internal bool SupportCustomOutputPaths
{
set { _mc.SupportCustomOutputPaths = value; }
}

// <summary>
// Start the compilation.
// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ internal static string GetWholeExceptionMessage(Exception exception)
//
// Helper to create CompilerWrapper.
//
internal static CompilerWrapper CreateCompilerWrapper(bool fInSeparateDomain, ref AppDomain appDomain)
internal static CompilerWrapper CreateCompilerWrapper()
{
return new CompilerWrapper();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@
ExtraBuildControlFiles="@(ExtraBuildControlFiles)"
XamlDebuggingInformation="$(XamlDebuggingInformation)"
IsRunningInVisualStudio="$(BuildingInsideVisualStudio)"
OutputPath="$(IntermediateOutputPath)">
OutputPath="$(IntermediateOutputPath)"
SupportCustomOutputPaths="$(IncludePackageReferencesDuringMarkupCompilation)">

<Output ItemName="GeneratedBaml" TaskParameter="GeneratedBamlFiles"/>
<Output ItemName="GeneratedLocalizationFiles" TaskParameter="GeneratedLocalizationFiles" />
Expand Down Expand Up @@ -304,7 +305,8 @@
XamlDebuggingInformation="$(XamlDebuggingInformation)"
GeneratedBaml=""
OutputPath="$(IntermediateOutputPath)"
ContinueOnError="false" >
ContinueOnError="false"
SupportCustomOutputPaths="$(IncludePackageReferencesDuringMarkupCompilation)">

<!--
Output Items for MarkupCompilePass2
Expand Down Expand Up @@ -398,16 +400,31 @@
</PropertyGroup>

<!-- Collect the generated NuGet files from the parent project required to support PackageReferences. -->
<!--
Note that MSBuildProjectExtensionsPath defaults to BaseIntermediateOutputPath (Microsoft.Common.props)
unless it it set prior to importing the .NET SDK. In the WPF temp project, MSBuildProjectExtensionsPath
cannot be defined before the .NET SDK is imported, and always defaults to BaseIntermediateOutputPath.
-->

<ItemGroup Condition="'$(IncludePackageReferencesDuringMarkupCompilation)' != 'false'">
<_SourceGeneratedNuGetPropsAndTargets Include="$(MSBuildProjectExtensionsPath)$(_ParentProjectName)$(_ParentProjectExtension).nuget.g.props"/>
<_SourceGeneratedNuGetPropsAndTargets Include="$(MSBuildProjectExtensionsPath)$(_ParentProjectName)$(_ParentProjectExtension).nuget.g.targets"/>
<_SourceGeneratedNuGetPropsAndTargets Include="$(MSBuildProjectExtensionsPath)$(_ParentProjectName)$(_ParentProjectExtension).nuget.dgspec.json"/>

<_DestGeneratedNuGetPropsAndTargets Include="$(MSBuildProjectExtensionsPath)$(_TemporaryTargetAssemblyProjectName).nuget.g.props"/>
<_DestGeneratedNuGetPropsAndTargets Include="$(MSBuildProjectExtensionsPath)$(_TemporaryTargetAssemblyProjectName).nuget.g.targets"/>
<_DestGeneratedNuGetPropsAndTargets Include="$(MSBuildProjectExtensionsPath)$(_TemporaryTargetAssemblyProjectName).nuget.dgspec.json"/>
<_DestGeneratedNuGetPropsAndTargets Include="$(BaseIntermediateOutputPath)$(_TemporaryTargetAssemblyProjectName).nuget.g.props"/>
<_DestGeneratedNuGetPropsAndTargets Include="$(BaseIntermediateOutputPath)$(_TemporaryTargetAssemblyProjectName).nuget.g.targets"/>
<_DestGeneratedNuGetPropsAndTargets Include="$(BaseIntermediateOutputPath)$(_TemporaryTargetAssemblyProjectName).nuget.dgspec.json"/>
</ItemGroup>

<!-- Project assets and nuget.cache files must also be copied if a custom BaseIntermediateOutputPath is set. -->
<ItemGroup Condition="'$(IncludePackageReferencesDuringMarkupCompilation)' != 'false' and '$(_InitialBaseIntermediateOutputPath)' != '$(BaseIntermediateOutputPath)'">
<_SourceGeneratedNuGetPropsAndTargets Include="$(MSBuildProjectExtensionsPath)project.assets.json"/>
<_SourceGeneratedNuGetPropsAndTargets Include="$(MSBuildProjectExtensionsPath)project.nuget.cache"/>

<_DestGeneratedNuGetPropsAndTargets Include="$(BaseIntermediateOutputPath)project.assets.json"/>
<_DestGeneratedNuGetPropsAndTargets Include="$(BaseIntermediateOutputPath)project.nuget.cache"/>
</ItemGroup>

<!-- Copy the renamed outer project NuGet props/targets files to the MSBuildProjectExtensionsPath used by NuGet. -->
<Copy Condition="'$(IncludePackageReferencesDuringMarkupCompilation)' != 'false'"
SourceFiles="@(_SourceGeneratedNuGetPropsAndTargets)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,11 @@ public bool IsRunningInVisualStudio
set { _isRunningInVisualStudio = value; }
}

///<summary>
/// Support custom IntermediateOutputPath and BaseIntermediateOutputPath outside the project path
///</summary>
public bool SupportCustomOutputPaths { get; set; } = false;

///<summary>
/// Generated source code files for the given programing language.
///</summary>
Expand Down Expand Up @@ -1215,7 +1220,7 @@ private void DoMarkupCompilation()

try
{
compilerWrapper = TaskHelper.CreateCompilerWrapper(AlwaysCompileMarkupFilesInSeparateDomain, ref appDomain);
compilerWrapper = TaskHelper.CreateCompilerWrapper();

if (compilerWrapper != null)
{
Expand All @@ -1239,6 +1244,8 @@ private void DoMarkupCompilation()

compilerWrapper.ContentFiles = CompilerAnalyzer.ContentFiles;

compilerWrapper.SupportCustomOutputPaths = SupportCustomOutputPaths;

// Process Reference list here.
ArrayList referenceList = ProcessReferenceList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ public bool XamlDebuggingInformation
set { _xamlDebuggingInformation = value; }
}

///<summary>
/// Support custom IntermediateOutputPath and BaseIntermediateOutputPath outside the project path
///</summary>
public bool SupportCustomOutputPaths { get; set; } = false;

/// <summary>
/// Known reference paths hold referenced assemblies which are never changed during the build procedure.
/// such as references in GAC, in framework directory or framework SDK directory etc.
Expand Down Expand Up @@ -634,7 +639,7 @@ private void DoLocalReferenceMarkupCompilation(FileUnit localApplicationFile, Fi

try
{
compilerWrapper = TaskHelper.CreateCompilerWrapper(AlwaysCompileMarkupFilesInSeparateDomain, ref appDomain);
compilerWrapper = TaskHelper.CreateCompilerWrapper();

if (compilerWrapper != null)
{
Expand All @@ -645,6 +650,8 @@ private void DoLocalReferenceMarkupCompilation(FileUnit localApplicationFile, Fi
compilerWrapper.UnknownErrorID = UnknownErrorID;
compilerWrapper.XamlDebuggingInformation = XamlDebuggingInformation;

compilerWrapper.SupportCustomOutputPaths = SupportCustomOutputPaths;

compilerWrapper.TaskFileService = _taskFileService;

if (OutputType.Equals(SharedStrings.Exe) || OutputType.Equals(SharedStrings.WinExe))
Expand Down