MSBuild尝试构建exe而不是dll

时间:2014-05-06 13:53:38

标签: c# msbuild

我手动创建了一个.csproj文件,使用命令行工具msbuild运行,但是,当我尝试运行它时,它想要构建为exe。如何才能将其专门构建为dll?下面是.csproj文件中的代码和我执行的命令提示符:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <Reference Include="System" />
        <Reference Include="System.Core" />
        <Reference Include="System.Data.Linq" />
    </ItemGroup>
    <ItemGroup>
        <Compile Include="C:\testing\test.cs" />
        <Compile Include="C:\testing\test.Designer.cs" />
        <EmbeddedResource Include="C:\testing\test.resx" />
    </ItemGroup>
    <Target Name="Build">
        <Csc Sources="@(Compile)" 
             Resources="@(EmbeddedResource)" 
             References="@(Reference)" 
             TargetType="library"
             OutputAssembly="C:\testing\test.dll" />
    </Target>
    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

cmd: msbuild "C:\testing\test.csproj"

4 个答案:

答案 0 :(得分:4)

将其添加到您的csproj文件中:

<PropertyGroup>
  <OutputType>Library</OutputType>
</PropertyGroup>

<ItemGroup>声明之上。

答案 1 :(得分:0)

您需要将以下内容添加到项目文件中:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
  <OutputType>Library</OutputType>
  <!-- Other properties go here -->
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
  <OutputType>Library</OutputType>
  <!-- Other properties go here -->
</PropertyGroup>

您可以拥有更多平台,只需根据您的需要添加库。

或者您可以这样做:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
 <OutputType>Library</OutputType>
      <!-- Other properties go here -->
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
 <OutputType>Library</OutputType>
      <!-- Other properties go here -->
</PropertyGroup>

答案 2 :(得分:0)

导入Microsoft.CSharp.targets文件后,您将获得围绕它的所有生态系统的Build目标。

以下情况可行。请注意OutputType属性。

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <OutputType>Library</OutputType>    
    </PropertyGroup>
    <ItemGroup>
        <Reference Include="System" />
        <Reference Include="System.Core" />
        <Reference Include="System.Data.Linq" />
    </ItemGroup>
    <ItemGroup>
        <Compile Include="Class1.cs" />
    </ItemGroup>
    <!-- You don't need to call the Csc target as Build target is already there once you import the Microsoft.CSharp.targets file -->
    <!--<Target Name="Build">
        <Csc Sources="@(Compile)" 
             Resources="@(EmbeddedResource)" 
             References="@(Reference)" 
             TargetType="library"
             OutputAssembly="abc.dll" />
    </Target>-->
    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

答案 3 :(得分:0)

我想我发现了... 您必须在您的.csproj文件中包括这两行

from netCDF4 import Dataset

file1 = 'D:\DATA\gls_SWE5K_202001_NHEMI_SSMIS_v0.nc'
data = Dataset(file1, 'r')

TW=  data.variables['tw'][:]
Pre = data.variables['pre'][:]
Tem = data.variables['tem'][:]
Lonn = data.variables['lon'][:]
Lat = data.variables['lat'][:]
Time = data.variables['time'][:]

注意事项:单个项目文件可以创建WinExe类型或库类型...

相关问题