使用MSBuild在.csproj中包含文件
我有一个MSBuild脚本,可以在编译包含许多项目的解决方案之前实现一些操作。使用MSBuild在.csproj中包含文件,msbuild,csproj,assemblyinfo,Msbuild,Csproj,Assemblyinfo,我有一个MSBuild脚本,可以在编译包含许多项目的解决方案之前实现一些操作。 我需要在每个项目属性文件夹中包含一个在此过程中创建的文件(SharedAssemblyInfo_$(ambiente).cs)。 有解决这个问题的线索吗? 提前谢谢 注:这是我的剧本: <?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
我需要在每个项目属性文件夹中包含一个在此过程中创建的文件(SharedAssemblyInfo_$(ambiente).cs)。
有解决这个问题的线索吗?
提前谢谢 注:这是我的剧本:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets"/>
<ItemGroup>
<Solution Include="Stoque.ECM.sln" />
<Compile Include="..\SharedAssemblyInfo_$(ambiente).cs">
<Link>Properties\SharedAssemblyInfo_$(ambiente).cs</Link>
</Compile>
</ItemGroup>
<PropertyGroup>
<TMaior>2</TMaior>
<TMedio>0</TMedio>
<TMenor>0</TMenor>
<DeployDir>E:\compartilhada\abaris</DeployDir>
</PropertyGroup>
<Target Name="GetProjects">
<GetSolutionProjects Solution="%(Solution.Fullpath)">
<Output ItemName="ProjectFiles" TaskParameter="Output" />
</GetSolutionProjects>
</Target>
<Target Name="AssemblyVersion">
<Time Format="yyMMdd">
<Output TaskParameter="FormattedTime" PropertyName="TRevisao" />
</Time>
<AssemblyInfo CodeLanguage="CS" OutputFile="..\SharedAssemblyInfo_$(ambiente).cs" AssemblyVersion="$(TMaior).$(TMenor).*" AssemblyFileVersion="$(versao)" AssemblyInformationalVersion="$(versao)" />
<!-- <Copy SourceFiles="..\SharedAssemblyInfo_$(ambiente).cs" DestinationFolder="%(ProjectFiles.Filename)\Properties" ContinueOnError="false" /> -->
</Target>
<Target Name="Compile" DependsOnTargets="GetProjects">
<MSBuild Projects="%(ProjectFiles.Fullpath)"
Properties="WebProjectOutputDir=$(DeployDir)\$(ambiente)\$(versao)\SITES_PUBLICADOS\%(ProjectFiles.Filename);Platform=$(Platform);Configuration=$(Configuration);OutputPath=$(DeployDir)\$(ambiente)\$(versao)\%(ProjectFiles.Filename)">
</MSBuild>
</Target>
</Project>
Properties\SharedAssemblyInfo_u$(ambiente).cs
2.
0
0
E:\comparilhada\abaris
我看到在根MSBuild.proj中有一个->项。这是一个很好的第一步,但您需要在实际的.csproj中坚持这一点,而不仅仅是在构建脚本中
要做到这一点,请将BeforeBuild任务添加到每个.csproj中,该.csproj添加到您想要作为链接的文件中
比如:
<Target Name="BeforeBuild">
<_FilesToInclude Include="..\SharedAssemblyInfo_$(ambiente).cs" />
<Compile Include="@(_FilesToInclude->'%(Filename)%(Extension)')">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
</ItemGroup>
</Target>
%(RecursiveDir)%(文件名)%(扩展名)