简体   繁体   English

在 Visual Studio 中使用自定义应用程序根文件夹发布 c# 项目

[英]Publish c# Project with Custom App Root folder in Visual Studio

I kindly need some assistance.我需要一些帮助。 I have finalized coding my application which works fine but i'm getting a bit of challenge publishing the app.我已经完成了我的应用程序的编码,它工作正常,但我在发布应用程序时遇到了一些挑战。 I have managed to copy the database to the output directory however, adding the images directory to the output directory has become very big issue to me.我已经设法将数据库复制到输出目录,但是,将图像目录添加到输出目录对我来说已经成为一个很大的问题。 The image directory contains custom images uploadable via the app.图像目录包含可通过应用上传的自定义图像。 I did some changes to the .csproj but in vain.我对 .csproj 做了一些更改,但没有用。

.csproj .csproj

<Target Name="ContentsBeforeBuild" AfterTargets="BeforeBuild">
    <ItemGroup>
      <Content Include="images\*.*">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </Content>
    </ItemGroup>
  </Target>

and also used并且还使用了

<Target Name="ContentsBeforeBuild" AfterTargets="BeforeBuild">
    <ItemGroup>
      <Content Include="images\**">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </Content>
    </ItemGroup>
  </Target>

And this is the code for retrieving and displaying the images onto my app.这是用于检索图像并将其显示到我的应用程序上的代码。 It works fine before publishing the app but after publishing, it returns directory notfound exception.在发布应用程序之前它工作正常,但在发布之后,它返回目录未找到异常。

 String paths = Application.StartupPath.Substring(0, (Application.StartupPath.Length - 10));

                    String imagePath = paths+"\\images\\"+col["itemPhoto"].ToString();

The error.错误。 Unable to access the image directory after publishing发布后无法访问图片目录

图像未找到目录错误

Is their any other way i can write the code so that it gets the images from the app?他们还有其他方式可以编写代码以便从应用程序获取图像吗? Kindy i need some assistance.善良,我需要一些帮助。

Over a week trying to publish my app .. Please please help一个多星期试图发布我的应用程序..请帮忙

.csproj .csproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{5765EB29-19B9-4FC8-8414-B033C956AE48}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Shop_POS</RootNamespace>
    <AssemblyName>Shop POS</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <PublishUrl>C:\Users\dansyo\Desktop\pos\spos\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>2</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <UseApplicationTrust>false</UseApplicationTrust>
    <PublishWizardCompleted>true</PublishWizardCompleted>
    <BootstrapperEnabled>true</BootstrapperEnabled>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup>
    <ApplicationIcon>logo1_15W_icon.ico</ApplicationIcon>
  </PropertyGroup>
  <PropertyGroup>
    <ManifestCertificateThumbprint>986913D78C02BC6448BB7EBB687285F9D3AB2FD4</ManifestCertificateThumbprint>
  </PropertyGroup>
  <PropertyGroup>
    <ManifestKeyFile>Shop POS_TemporaryKey.pfx</ManifestKeyFile>
  </PropertyGroup>
  <PropertyGroup>
    <GenerateManifests>true</GenerateManifests>
  </PropertyGroup>
  <PropertyGroup>
    <SignManifests>true</SignManifests>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.DirectoryServices" />
    <Reference Include="System.Windows.Forms.DataVisualization" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Deployment" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="AddEmployeeDialog.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="AddEmployeeDialog.Designer.cs">
      <DependentUpon>AddEmployeeDialog.cs</DependentUpon>
    </Compile>
    <Compile Include="AddItemDialog.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="AddItemDialog.Designer.cs">
      <DependentUpon>AddItemDialog.cs</DependentUpon>
    </Compile>
    <Compile Include="ComboboxItem.cs" />
    <Compile Include="BusinessProfile.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="BusinessProfile.Designer.cs">
      <DependentUpon>BusinessProfile.cs</DependentUpon>
    </Compile>
    <Compile Include="DatabaseHandler.cs" />
    <Compile Include="DeleteAlldata.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="DeleteAlldata.Designer.cs">
      <DependentUpon>DeleteAlldata.cs</DependentUpon>
    </Compile>
    <Compile Include="ForgottenPassword.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="ForgottenPassword.Designer.cs">
      <DependentUpon>ForgottenPassword.cs</DependentUpon>
    </Compile>
    <Compile Include="GenerateBarCode.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="GenerateBarCode.Designer.cs">
      <DependentUpon>GenerateBarCode.cs</DependentUpon>
    </Compile>
    <Compile Include="GenerateBarCodeDialog.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="GenerateBarCodeDialog.Designer.cs">
      <DependentUpon>GenerateBarCodeDialog.cs</DependentUpon>
    </Compile>
    <Compile Include="OutOfStock.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="OutOfStock.Designer.cs">
      <DependentUpon>OutOfStock.cs</DependentUpon>
    </Compile>
    <Compile Include="PremiumActivation.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="PremiumActivation.Designer.cs">
      <DependentUpon>PremiumActivation.cs</DependentUpon>
    </Compile>
    <Compile Include="RecoverAccount.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="RecoverAccount.Designer.cs">
      <DependentUpon>RecoverAccount.cs</DependentUpon>
    </Compile>
    <Compile Include="Getter.cs" />
    <Compile Include="MainActivity.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="MainActivity.Designer.cs">
      <DependentUpon>MainActivity.cs</DependentUpon>
    </Compile>
    <Compile Include="Login.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="Login.Designer.cs">
      <DependentUpon>Login.cs</DependentUpon>
    </Compile>
    <Compile Include="Methods.cs" />
    <Compile Include="PrintMyCart.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="PrintMyCart.Designer.cs">
      <DependentUpon>PrintMyCart.cs</DependentUpon>
    </Compile>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Register.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="Register.Designer.cs">
      <DependentUpon>Register.cs</DependentUpon>
    </Compile>
    <Compile Include="ResetPassword.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="ResetPassword.Designer.cs">
      <DependentUpon>ResetPassword.cs</DependentUpon>
    </Compile>
    <Compile Include="RestoreDefault.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="RestoreDefault.Designer.cs">
      <DependentUpon>RestoreDefault.cs</DependentUpon>
    </Compile>
    <Compile Include="SellerActivity.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="SellerActivity.Designer.cs">
      <DependentUpon>SellerActivity.cs</DependentUpon>
    </Compile>
    <Compile Include="EmpMethod.cs" />
    <Compile Include="SellerActivitySearchInventory.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="SellerActivitySearchInventory.Designer.cs">
      <DependentUpon>SellerActivitySearchInventory.cs</DependentUpon>
    </Compile>
    <Compile Include="Splash.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="Splash.Designer.cs">
      <DependentUpon>Splash.cs</DependentUpon>
    </Compile>
    <Compile Include="TaxDialog.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="TaxDialog.Designer.cs">
      <DependentUpon>TaxDialog.cs</DependentUpon>
    </Compile>
    <Compile Include="TblCompanyProfile.cs" />
    <Compile Include="TblInventory.cs" />
    <Compile Include="TblRegister.cs" />
    <Compile Include="TblSales.cs" />
    <Compile Include="TblSellers.cs" />
    <Compile Include="TblSettings.cs" />
    <Compile Include="UpdateDelEmpDialog.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="UpdateDelEmpDialog.Designer.cs">
      <DependentUpon>UpdateDelEmpDialog.cs</DependentUpon>
    </Compile>
    <Compile Include="UpdateDelInventoryDialog.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="UpdateDelInventoryDialog.Designer.cs">
      <DependentUpon>UpdateDelInventoryDialog.cs</DependentUpon>
    </Compile>
    <EmbeddedResource Include="AddEmployeeDialog.resx">
      <DependentUpon>AddEmployeeDialog.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="AddItemDialog.resx">
      <DependentUpon>AddItemDialog.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="BusinessProfile.resx">
      <DependentUpon>BusinessProfile.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="DeleteAlldata.resx">
      <DependentUpon>DeleteAlldata.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="ForgottenPassword.resx">
      <DependentUpon>ForgottenPassword.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="GenerateBarCode.resx">
      <DependentUpon>GenerateBarCode.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="GenerateBarCodeDialog.resx">
      <DependentUpon>GenerateBarCodeDialog.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="OutOfStock.resx">
      <DependentUpon>OutOfStock.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="PremiumActivation.resx">
      <DependentUpon>PremiumActivation.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="RecoverAccount.resx">
      <DependentUpon>RecoverAccount.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="MainActivity.resx">
      <DependentUpon>MainActivity.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="Login.resx">
      <DependentUpon>Login.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="PrintMyCart.resx">
      <DependentUpon>PrintMyCart.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
      <SubType>Designer</SubType>
    </EmbeddedResource>
    <Compile Include="Properties\Resources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
      <DesignTime>True</DesignTime>
    </Compile>
    <EmbeddedResource Include="Register.resx">
      <DependentUpon>Register.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="ResetPassword.resx">
      <DependentUpon>ResetPassword.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="RestoreDefault.resx">
      <DependentUpon>RestoreDefault.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="SellerActivity.resx">
      <DependentUpon>SellerActivity.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="SellerActivitySearchInventory.resx">
      <DependentUpon>SellerActivitySearchInventory.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="Splash.resx">
      <DependentUpon>Splash.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="TaxDialog.resx">
      <DependentUpon>TaxDialog.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="UpdateDelEmpDialog.resx">
      <DependentUpon>UpdateDelEmpDialog.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="UpdateDelInventoryDialog.resx">
      <DependentUpon>UpdateDelInventoryDialog.cs</DependentUpon>
    </EmbeddedResource>
    <None Include="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
    <None Include="Shop POS_TemporaryKey.pfx" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="images\**">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="logo\**">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="favicon.ico" />
    <Content Include="images\alfa_romeo.jpg" />
    <Content Include="logo1_15W_icon.ico" />
    <Content Include="logo\DAEWOO.jpg" />
    <Content Include="Properties\add.png" />
    <None Include="Resources\za.png" />
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include=".NETFramework,Version=v4.5">
      <Visible>False</Visible>
      <ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <ItemGroup />

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

I think the issue is the way how you are trying to access images folder.我认为问题在于您尝试访问图像文件夹的方式。 Like I said in my comment, the path won't match after you deploy the application (as you are doing substring).就像我在评论中所说的那样,部署应用程序后路径将不匹配(因为您正在执行子字符串)。

Since you are copying images folder, you don't need to do substring.由于您正在复制图像文件夹,因此您不需要执行子字符串。

Just try this:试试这个:

String imagePath = Application.StartupPath+"\\images\\"+col["itemPhoto"].ToString();

Could you modify your csproj file,你能修改你的csproj文件吗,

<ItemGroup>
  <Content Include="images\alfa_romeo.jpg">
     <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Content>    
</ItemGroup>

and remove your existing并删除您现有的

  <ItemGroup>
    <Content Include="images\**">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

and this line:和这一行:

在此处输入图片说明

Thanks Guy.哥们,谢啦。 Finally i had to do it programmatically and it worked.最后我不得不以编程方式完成它并且它起作用了。 I added the images directory programmatically on my app launch and worked amazing.我在我的应用程序启动时以编程方式添加了图像目录,效果非常好。

 bool exists = System.IO.Directory.Exists("images");

            if (!exists)
                System.IO.Directory.CreateDirectory("images");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM