C# 在运行时获取$(SolutionDir)
我已使用以下任务设法在运行时获取$(SolutionDir)变量:C# 在运行时获取$(SolutionDir),c#,visual-studio-2008,msbuild,task,C#,Visual Studio 2008,Msbuild,Task,我已使用以下任务设法在运行时获取$(SolutionDir)变量: <Target Name="GenerateCode" Outputs="$(IntermediateOutputPath)ResourcesPath-Constants.cs"> <Exec Command= " echo namespace SRE.Widgets.Blend > $(IntermediateOutputPath)ResourcesPath-
<Target Name="GenerateCode" Outputs="$(IntermediateOutputPath)ResourcesPath-Constants.cs">
<Exec Command=
"
echo namespace SRE.Widgets.Blend > $(IntermediateOutputPath)ResourcesPath-Constants.cs
echo { >> $(IntermediateOutputPath)ResourcesPath-Constants.cs
echo public static partial class ResourcesPath >> $(IntermediateOutputPath)ResourcesPath-Constants.cs
echo { >> $(IntermediateOutputPath)ResourcesPath-Constants.cs
echo public static string SOLUTION_DIR = @"$(SolutionDir)"; >> $(IntermediateOutputPath)ResourcesPath-Constants.cs
echo } >> $(IntermediateOutputPath)ResourcesPath-Constants.cs
echo } >> $(IntermediateOutputPath)ResourcesPath-Constants.cs
" />
</Target>
<Target Name="CompileGeneratedCode">
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)ResourcesPath-Constants.cs" />
</ItemGroup>
</Target>
<PropertyGroup>
<CompileDependsOn>
GenerateCode;
CompileGeneratedCode;
$(CompileDependsOn);
</CompileDependsOn>
</PropertyGroup>
生成代码;
编译生成代码;
美元(已编撰);
我的问题是,由于任务没有“输入”,所以这个项目总是构建的。这很奇怪,因为它破坏了增量编译。这个项目是用在不同的解决方案,我只希望它被编译,如果我改变了解决方案
我已尝试使用Inputs=“$(SolutionPath)。如果只使用一个解决方案,此方法效果很好,但当使用另一个解决方案的项目时,sln.cache会损坏并永远停止构建任务。无论是否删除“Inputs”变量。使其重新工作的唯一方法是删除.sln.cache文件
有人知道有什么方法可以阻止每次编译项目吗
编辑:
好的,我找到了解决方案:
<Target Name="GenerateTmpCode">
<Exec
Command=
"
echo namespace SRE.Widgets.Blend > $(IntermediateOutputPath)ResourcesPath-Constants.g.cs.tmp
echo { >> $(IntermediateOutputPath)ResourcesPath-Constants.g.cs.tmp
echo public static partial class ResourcesPath >> $(IntermediateOutputPath)ResourcesPath-Constants.g.cs.tmp
echo { >> $(IntermediateOutputPath)ResourcesPath-Constants.g.cs.tmp
echo public static string SOLUTION_DIR = @"$(SolutionDir)"; >> $(IntermediateOutputPath)ResourcesPath-Constants.g.cs.tmp
echo } >> $(IntermediateOutputPath)ResourcesPath-Constants.g.cs.tmp
echo } >> $(IntermediateOutputPath)ResourcesPath-Constants.g.cs.tmp
fc $(IntermediateOutputPath)ResourcesPath-Constants.g.cs.tmp $(IntermediateOutputPath)ResourcesPath-Constants.g.cs
"
ContinueOnError="true">
<Output PropertyName="CommandExitCode" TaskParameter="ExitCode"/>
</Exec>
</Target>
<Target Name="GenerateCode"
Condition="'$(CommandExitCode)'!='0'"
Outputs="$(IntermediateOutputPath)ResourcesPath-Constants.cs"
Inputs="$(IntermediateOutputPath)ResourcesPath-Constants.g.cs.tmp" >
<Exec Command=
"
copy $(IntermediateOutputPath)ResourcesPath-Constants.g.cs.tmp $(IntermediateOutputPath)ResourcesPath-Constants.g.cs
" />
</Target>
<Target Name="CompileGeneratedCode">
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)ResourcesPath-Constants.g.cs">
<AutoGen>True</AutoGen>
</Compile>
</ItemGroup>
</Target>
<PropertyGroup>
<CompileDependsOn>
GenerateTmpCode;
GenerateCode;
CompileGeneratedCode;
$(CompileDependsOn);
</CompileDependsOn>
</PropertyGroup>
符合事实的
生成mpcode;
生成代码;
编译生成代码;
美元(已编撰);
有两个目标。第一个目标在临时文件中创建一个包含$(solutiondir)值字符串的分部类,并将其与当前使用的分部类进行比较。第二个目标在必要时将临时文件复制到当前分部类上。您是否考虑过一些可以添加的有效输入,例如ApplicationInfo.cs(版本)文件?Merlyn,你是说AssemblyInfo.cs吗?当我从不同的解决方案打开项目时,此文件不会更改。我需要重新编译此项目,如果我从不同的解决方案使用它。谢谢。我只是想让此项目成为一个项目,并为其提供输入。我假设你的意思是没有输入文件,所以它不知道何时重新编译,因此添加了一些有意义的文件(例如AssemblyInfo.cs)。