如何将文档xml文件构建到适当的路径?

时间:2014-04-03 16:33:01

标签: c# .net visual-studio

我想为我的C#项目构建文档xml文件。我怎么能这样做?

这是我的CommonBase.props文件,由大约一百个csproj个文件导入。重点是在不同的地方保存编辑相同的信息。

我想将文档构建到下面的OutputPath。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- Common properties for  projects. This project can't be built by itself, but is imported by several projects. Be careful to prepend $(MSBuildThisFileDirectory) before any paths relative to this file.

    If you import this project from a csproj file, you should still define at least ProjectGuid, AssemblyName, RootNamespace and OutputType in the csproj.  
  -->
  <PropertyGroup>
    <!-- If configuration not specified, default to debug. If platform not specified, default to x64. Necessary for London continuous integration server. -->
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x64</Platform>

    <PlatformTarget>$(Platform)</PlatformTarget>
    <ProductVersion>9.0.30729</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <DebugSymbols>true</DebugSymbols>
    <ErrorReport>prompt</ErrorReport>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Platform)' == 'x86'">
    <OutputPath>$(MSBuildThisFileDirectory)..\..\bin32\</OutputPath>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Platform)' == 'x64'">
    <OutputPath>$(MSBuildThisFileDirectory)..\..\bin\</OutputPath>
  </PropertyGroup>
</Project>

这就是csproj的样子

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <Import Project="..\Build\CommonBase.props" />

2 个答案:

答案 0 :(得分:7)

您需要将以下行添加到csproject文件中:<DocumentationFile>bin\Debug\ProjectName.XML</DocumentationFile>(在PropertyGroup下)

在Project Properties中,您可以使用“XML Documentation File”复选框手动将其放入Build选项卡中。

或者使用代码一次更改许多项目文件:

var projectFiles = System.IO.Directory.GetFiles(
    @"C:\somePath", "*.csproj", SearchOption.AllDirectories);

foreach (var file in projectFiles)
{
    var xmlFile = XDocument.Load(file);
    var propNode = xmlFile.Root.Elements().First();
    var assemblyName = propNode.Elements().First(x =>x.Name.LocalName == "AssemblyName").Value;
    propNode.Add(new XElement("DocumentationFile", string.Format("somePlace\\{0}.XML", assemblyName)));
    xmlFile.Save(file);
}

答案 1 :(得分:0)

我可以使用模板编写文件路径:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DocumentationFile>$(MSBuildThisFileDirectory)\bin\$(Configuration)\$(TargetFramework)\<File_Name>.xml</DocumentationFile>
  </PropertyGroup>