Skip to content

Commit 7097952

Browse files
yevhenclaude
andcommitted
Fix MSBuild targets to preserve unprocessed source files
The previous implementation removed ALL source files from compilation and only included rewritten files. This broke namespace resolution for types in files without Assert() calls (like PipeMock). This fix: - Only removes files that were actually rewritten - Includes both rewritten files AND unprocessed source files - Preserves the complete compilation context Fixes namespace resolution errors like: CS0103: The name 'PipeMock' does not exist in the current context 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 01b3528 commit 7097952

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using static SharpAssert.Sharp;
2+
3+
namespace SharpAssert.IntegrationTests;
4+
5+
[TestFixture]
6+
public class ReferencedFilesFixture
7+
{
8+
[Test]
9+
public void Test_can_use_code_in_non_rewritten_files()
10+
{
11+
var helper = new TestHelper();
12+
helper.Increment();
13+
14+
Assert(helper.Count > 0);
15+
}
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace SharpAssert.IntegrationTests;
2+
3+
public class TestHelper
4+
{
5+
public int Count = 42;
6+
public void Increment() => Count++;
7+
}

src/SharpAssert/build/SharpAssert.targets

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,23 @@
4141
<ItemGroup>
4242
<!-- Track rewritten files for potential cleanup -->
4343
<_SharpRewrittenFiles Include="$(IntermediateOutputPath)SharpRewritten\**\*.sharp.g.cs" />
44-
<!-- Only during actual build: swap original files with rewritten versions -->
45-
<Compile Remove="@(_SharpSourceFiles)" />
44+
45+
<!-- Identify which source files were actually rewritten -->
46+
<_SharpProcessedSources Include="@(_SharpSourceFiles)"
47+
Condition="Exists('$(IntermediateOutputPath)SharpRewritten\%(RecursiveDir)%(Filename)%(Extension).sharp.g.cs')" />
48+
49+
<!-- Find source files that weren't processed (no Assert calls) -->
50+
<_SharpUnprocessedSources Include="@(_SharpSourceFiles)"
51+
Exclude="@(_SharpProcessedSources)" />
52+
53+
<!-- Only remove files that were actually rewritten -->
54+
<Compile Remove="@(_SharpProcessedSources)" />
55+
56+
<!-- Include only rewritten files -->
4657
<Compile Include="@(_SharpRewrittenFiles)" />
4758
</ItemGroup>
4859

49-
<Message Text="SharpAssert: Replaced @(_SharpSourceFiles->Count()) source files with rewritten versions (actual build)" Importance="normal"
60+
<Message Text="SharpAssert: Processed @(_SharpProcessedSources->Count()) of @(_SharpSourceFiles->Count()) source files, preserved @(_SharpUnprocessedSources->Count()) unmodified files" Importance="normal"
5061
Condition="'$(SharpAssertEmitRewriteInfo)'=='true'" />
5162

5263
</Target>

0 commit comments

Comments
 (0)